From patchwork Sun Mar 17 10:40:31 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: 13594543 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14FDF1AAA5 for ; Sun, 17 Mar 2024 10:41:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710672061; cv=none; b=cdq4qlLNUs4F9AGQ9yGibJxWLOgPQJ2v/nxrjMUFxD3+CGPW6SDmWul3Joiu2AvrBV4DEpFIkUw5c0wZmEOn1bJz3hdMKkEa21ARiVISjglqOaXEAwzxAgIgo/fsG7ev5hxxBE3PuZliCR+s5TBXh+uyvimcdYhl7YMHjOFvLt0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710672061; c=relaxed/simple; bh=fs59cnUdx6Lj37sKccMDB1aCfsDJsVT37Vt+S8/sLfQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=j0AHSdhGrTQmECRMkgwbuDlrNon5dzyZAcdIADpwbMwWNFMUVVb2L65TUm/y22DAt73OBdfYwAQ8c+lZLYi7JRdGZ2oQl8DHybenzCyv4g/5yphJB9PQYWEF6b5m4xrQ3a8fGkf4T8zXy1yJOJwJ5r1v0YCnsqQxUOG9Bb9gdjI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rlnwd-00029Q-HI; Sun, 17 Mar 2024 11:40:47 +0100 Received: from [2a0a:edc0:0:900:1d::77] (helo=ptz.office.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rlnwc-006rff-RP; Sun, 17 Mar 2024 11:40:46 +0100 Received: from ukl by ptz.office.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1rlnwc-007aCv-2T; Sun, 17 Mar 2024 11:40:46 +0100 From: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= To: linux-pwm@vger.kernel.org Cc: kernel@pengutronix.de, Kees Cook , "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH 0/8] pwm: Add support for character devices Date: Sun, 17 Mar 2024 11:40:31 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2528; i=u.kleine-koenig@pengutronix.de; h=from:subject:message-id; bh=fs59cnUdx6Lj37sKccMDB1aCfsDJsVT37Vt+S8/sLfQ=; b=owGbwMvMwMXY3/A7olbonx/jabUkhtRvJxYsaufN39XgfXrBvIQF1e6v41KZjC8+TmOfnTX5e 9fxnD/5nYzGLAyMXAyyYoos9o1rMq2q5CI71/67DDOIlQlkCgMXpwBM5FwYB8M28/f5NyNsN0gI cMfs7cq6/9WWXbL4p1vVpVJOuxaz6yc8TEpVk6PPcmyV8bVbYr331V6zxH28DHu5dmiG7Y8O9L2 S0eDOF142LTFn+6nvx3Tk+t9o3a0zlWcvf/gm+JVO9dmPho8u2ey6UuJzWa6ij9XNp65b5nbylp mzFVeHh2YrPatabVtQfqlBLNK0ar05T0x60XUn71VTXdTdGk5pOs+p3S2TaLakK0LuS97WQhOTA pWVjwsu1ga++PktSlCNoXVLeMy9qI3Tg55bru8/9nU50x2LDw8YBRjfZn7ekcQTNcfbXu422/Tz fq65Kwoy5j8Q7pz376uZeEIB6/1n1zJnZc6ua5U46P4UAA== X-Developer-Key: i=u.kleine-koenig@pengutronix.de; a=openpgp; fpr=0D2511F322BFAB1C1580266BE2DCDD9132669BD6 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-hardening@vger.kernel.org Hello, After the necessary changes to the lowlevel drivers got in for v6.9-rc1 here come some changes to the core to implement /dev/pwmchipX character devices. In my tests on an ARM STM32MP1 programming a PWM using the character device is ~4 times faster than just changing duty_cycle via the sysfs API. It also has the advantage that (similar to pwm_apply_*) the target state is provided to the kernel with a single call, instead of having to program the individual settings one after another via sysfs (in the right order to not cross states not supported by the driver). Note the representation of a PWM waveform is different here compared to the in-kernel representation. A PWM waveform is represented using: period duty_cycle duty_offset A disabled PWM is represented by period = 0. For an inversed wave use: duty_offset = duty_cycle duty_cycle = period - duty_cycle; . However there are some difficulties yet that make it hard to provide a consistent API to userspace and so for now duty_offset isn't (fully) supported yet. That needs some more consideration and can be added later. A userspace lib together with some simple test programs making use of this new API can be found at https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/libpwm.git . The start of the series is some cleanup and preparation. The lifetime and locking patches are needed to not crash the kernel when a character device is open while a lowlevel driver goes away. I look forward to feedback, Uwe Uwe Kleine-König (8): pwm: Ensure that pwm_chips are allocated using pwmchip_alloc() pwm: Give some sysfs related variables and functions better names pwm: Move contents of sysfs.c into core.c pwm: Ensure a struct pwm has the same lifetime as its pwm_chip pwm: Add a struct device to struct pwm_chip pwm: Make pwmchip_[sg]et_drvdata() a wrapper around dev_set_drvdata() pwm: Add more locking pwm: Add support for pwmchip devices for faster and easier userspace access drivers/pwm/Kconfig | 4 - drivers/pwm/Makefile | 1 - drivers/pwm/core.c | 988 +++++++++++++++++++++++++++++++++++++-- drivers/pwm/sysfs.c | 545 --------------------- include/linux/pwm.h | 51 +- include/uapi/linux/pwm.h | 23 + 6 files changed, 993 insertions(+), 619 deletions(-) delete mode 100644 drivers/pwm/sysfs.c create mode 100644 include/uapi/linux/pwm.h base-commit: dd6c6d57ab61d496f6ff7d6ca38611062af142a1