From patchwork Fri Sep 20 08:57:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 13808370 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 91951CF58F4 for ; Fri, 20 Sep 2024 09:02:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version: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:In-Reply-To:References:List-Owner; bh=5T7rAchj5qjYDoyRW1lduedlZlpub5pg2seiU2N4rAs=; b=Nh3rB8OmoobKBk3+BNHV6Ksidz N4vK3teUshndi4QP2I6QddwRZHUwOD81nZVAtAokp3Y3Pro440606I2Xncx7ffxlAAIEJ+EoIuOVL 3NfC9pglb3pY01aGiL05ew3u1mB2VA4H3VUKd4BVHg7dT5FXj5xajxzRhp2blDFJdDacnQCrDmpDu YerhqWXYCKyFvftAEvHovUTpI8Tx/s9eGrhQCG1c6HDGt6BCnxscXk3RcmQ2HMc0pPKBCJ3HLplSS B3YGuWzVv5z1rXGTrq7b3BvUsnAnVyu9hDjWyggfS3+T/JsX87KwQAmAtl6O8PTeqlKrtyovA7fHM ZoOBVmCQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1srZWS-0000000BsDq-32UX; Fri, 20 Sep 2024 09:01:52 +0000 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1srZTH-0000000BrVZ-44l8 for linux-arm-kernel@lists.infradead.org; Fri, 20 Sep 2024 08:58:37 +0000 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-374d29ad870so1008335f8f.3 for ; Fri, 20 Sep 2024 01:58:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1726822714; x=1727427514; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=5T7rAchj5qjYDoyRW1lduedlZlpub5pg2seiU2N4rAs=; b=di1Knary3qPO50OX4rSnc+OZRVsO2ifgGbh09i0eGULQSgVgVE+9P6vJIWAoBA8r8a BGfLOqvLJoYi/95AQJ33qe8YyYTJkUogapjit8W/bh3ps/IfBd5Rm/GJkzpdE0JB7dze uXa1k81tNAuloetcX7W5CrTgf1u40yXhMD8S+4qK/v7vmzwbIDglpA63J8VvXks0yyxR LQ9LSkKAACI5gQ33r694W0ChlnJeg+so7RZ2bytsqtae4QlErumdqlQsLQsagGdFNvFh 5DXWSX+wZy47xiSA4RaiuGsi10tmSWqaKOh/wkkNckXHm8I6oGheaI90P+xkrwx0ZBHY 9oFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726822714; x=1727427514; 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=5T7rAchj5qjYDoyRW1lduedlZlpub5pg2seiU2N4rAs=; b=EPlUhsm1YkCqlBtS05MP9rzEiBdS6psIYLegHbwYkZCxLLhSY1D3eWHnTtdXMpvcm5 Hz5om8Dx6OYXhqppsQE8Sa+gBV6rwsZWtbjWKsqfzEMzBjSAiU28zr4/zSjFl/P+VbOb zYcgIJXqshXCZ8HABGRpvHEJkTZfeMx7K0OralBJ6P+VyUL3SdQQzQqAOsGy7W7pc5W7 aPezt8OcZ6GCjQAJQQC3vTESX5xE7H10QV6L488vjeYVFWdrI96p70yUAQR/lLktN7tM So4wixqwGGHgPyB+Sh+fILzj4hCPgAMfbWcbTvHC9XIgkj3VFeaYYlCiuRAEGAObgRph D2Wg== X-Forwarded-Encrypted: i=1; AJvYcCV/1lUMQnyrZweCojqhbJ/oRRmD866ECcQk+Cs8Dg9NLctxkzhHVscs1NZPEaPx61iT74D9ejdnDSd+Yelg2TDB@lists.infradead.org X-Gm-Message-State: AOJu0YxGvvUjBHwssL2JShCmeObanUr23EhKyCQ7TA0J5MCEODBNco3R GchNH0k347xaYPrR3effYNti1NL7BTVk4z0rQapL/cEmlU7DzqegujRMZYV7CSM= X-Google-Smtp-Source: AGHT+IFiyYUeet0rXnG7rQ+wSp502xhgfbMgHAX8ZnoNks935ZvuxAODvTuqZ89H56rGe8FXixFBRQ== X-Received: by 2002:a5d:6646:0:b0:378:89d8:8242 with SMTP id ffacd0b85a97d-37a422bf176mr1194672f8f.26.1726822714017; Fri, 20 Sep 2024 01:58:34 -0700 (PDT) Received: from localhost (p200300f65f01db004d6a46a6454a1385.dip0.t-ipconnect.de. [2003:f6:5f01:db00:4d6a:46a6:454a:1385]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378e71f060bsm17253187f8f.1.2024.09.20.01.58.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2024 01:58:33 -0700 (PDT) From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Trevor Gamblin , David Lechner , Kent Gibson , Fabrice Gasnier , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , linux-trace-kernel@vger.kernel.org, Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Maxime Coquelin , Alexandre Torgue , linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH v5 0/8] pwm: New abstraction and userspace API Date: Fri, 20 Sep 2024 10:57:56 +0200 Message-ID: X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4775; i=u.kleine-koenig@baylibre.com; h=from:subject:message-id; bh=te+EbZlOUzUoKfESPB4idPRylkC8d1cHg4R/EUUCx30=; b=owEBbQGS/pANAwAKAY+A+1h9Ev5OAcsmYgBm7TkV/hf2RR9pvgUEH/B4lFQkjy6tkOym4gxCC vSZyuCbZu2JATMEAAEKAB0WIQQ/gaxpOnoeWYmt/tOPgPtYfRL+TgUCZu05FQAKCRCPgPtYfRL+ Tvt+B/9MeZwymukRVIoG7lg3WRNuWiKios+vhDimsAp5YqaQUrWoPlJXQQQE3OxiVqTlfEWmIWZ RMfLrxP51RUnl2ohTkJ2+UWZypzOdCyQ9SqPuz+m7pYTSxhEAKnN76IDUK4FFhfgCup/PwG4Xx8 02m8ui24J/3AO/9F0mkibyoI2xseAU4DUMdUUU8pDTFeGzI0E6+r/uu9cxc+hXEE4CkGIy7Lis+ CK+7e5KbyBw/Nu2djwDD/lUFniw6PqVcXqHTQuMq/ESlAtHzU9zYEsku8b6DFEiQV/ljUZ6FzkL p29TKSASh7D360Iquptb5Pg/WKyZTmMf+mMitPW3UmG8bthV X-Developer-Key: i=u.kleine-koenig@baylibre.com; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240920_015836_058601_F4B3F08E X-CRM114-Status: GOOD ( 29.04 ) 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 Hello, here comes v5 of the series to add support for duty offset in PWM waveforms. With that (and using two PWMs of a single chip) the following waveform pair can be configured: ______ ______ ______ ______ PWM #0 ___/ \_______/ \_______/ \_______/ \_______ __ __ __ __ PWM #1 _____/ \___________/ \___________/ \___________/ \_________ ^ ^ ^ ^ This is required for an adc driver by Trevor Gamblin[1]. The last patch also adds a new userspace API using a character device per pwm_chip (if the underlaying lowlevel driver support the new waveform callbacks). Compared to the earlier revisions of this series it was moved to the last patch because I don't intend to apply it during the next development cycle. The reason that makes me hesitate is that the return value convention by the .round_waveform_tohw() callback is unusual: It returns either 0 or 1 or a negative error value. These return values are passed to userspace as the return value of the added ioctl() calls and so are not changable any more once they are considered part of the userspace API. So for now the pwm internal convention stays unusual as it was before, but can still be easily adapted if practise showed the convention to be too bad to keep. If you want to test this series, the current state is available at https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git pwm/chardev . Changes since v4 which is available at https://lore.kernel.org/linux-pwm/cover.1725635013.git.u.kleine-koenig@baylibre.com : - As described above: New patch to reorder symbols in core.c and the character device patch is moved to the end. - PWM_IOCTL_REQUEST is now mandatory before using a pwm device via the pwmchip character device. Thanks to David for input here. The libpwm repo[2] is updated accordingly. - PWM_IOCTL_REQUEST and PWM_IOCTL_FREE calling convention changed. Before you had to do: someuint = 3; ioctl(pwmchipfd, PWM_IOCTL_REQUEST, &someuint); Now it's just: ioctl(pwmchipfd, PWM_IOCTL_REQUEST, 3); - There is a new patch that reorders functions in drivers/pwm/core.c. The motivation for that was a locking issue in the ioctl code where pwm_lock was taken twice on PWM_IOCTL_FREE. So a new variant of pwm_put() was introduced that relies on the caller to have grabbed the lock already. To not have to declare this new function, it had to be moved further up in core.c - Some debugging code removed. (huh, thanks to David for noticing.) - Additions to comments (also kernel doc) and commit logs for several patches to (hopefully) make things clearer. - Refactored how the input is validated for the PWM_IOCTL_SET*WF ioctls to remove code duplication. (IIRC this was feedback on an earlier revision. But I only remembered it and couldn't find it in my mailbox. I think it was Fabrice who wrote that, but I'm not entirely sure. Thanks to whoever it was.) Unless something grave pops up, I intend to add this series (without the last patch) to next after the merge window closes to give it some more exposure and testing. I'm pretty sure the code still has to be fixed and improved here and there, but I will do that in-tree then. Once I'm sure it will go in, I'll create a tag for Jonathan to merge into his iio tree to allow him to apply Trevor's adc driver. @Jonathan: What's your desired timing? I'd target for around -rc3 time to create that tag for you. Is that early enough for you? Best regards Uwe [1] https://lore.kernel.org/linux-iio/20240909-ad7625_r1-v5-0-60a397768b25@baylibre.com [2] https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/libpwm.git Uwe Kleine-König (8): pwm: Add more locking pwm: New abstraction for PWM waveforms pwm: Provide new consumer API functions for waveforms pwm: Add tracing for waveform callbacks pwm: axi-pwmgen: Implementation of the waveform callbacks pwm: stm32: Implementation of the waveform callbacks pwm: Reorder symbols in core.c pwm: Add support for pwmchip devices for faster and easier userspace access drivers/pwm/core.c | 1144 +++++++++++++++++++++++++++++----- drivers/pwm/pwm-axi-pwmgen.c | 154 +++-- drivers/pwm/pwm-stm32.c | 612 +++++++++++------- include/linux/pwm.h | 58 +- include/trace/events/pwm.h | 134 +++- include/uapi/linux/pwm.h | 32 + 6 files changed, 1693 insertions(+), 441 deletions(-) create mode 100644 include/uapi/linux/pwm.h base-commit: d242feaf81d63b25d8c1fb1a68738dc33966a376