mbox series

[0/3] Add Intel 8254 Counter support

Message ID cover.1681665189.git.william.gray@linaro.org
Headers show
Series Add Intel 8254 Counter support | expand

Message

William Breathitt Gray April 16, 2023, 5:36 p.m. UTC
The Intel 8254 PIT first appeared in the early 1980s and was used
initially in IBM PC compatibles. The popularity of the original Intel
825x family of chips led to many subsequent variants and clones of the
interface in various chips and integrated circuits. Although still
popular, interfaces compatible with the Intel 8254 PIT are nowdays
typically found embedded in larger VLSI processing chips and FPGA
components rather than as discrete ICs.

This patch series introduces a library to provide support for interfaces
compatible with the venerable Intel 8254 Programmable Interval Timer
(PIT). Modules wanting access to the i8254 library should select the
newly introduced CONFIG_I8254 Kconfig option, and import the I8254
symbol namespace.

Support for the i8254 is added in respective follow-up patches for the
104-dio-48e driver and stx104 driver whose devices feature i8254
compatible interfaces. Several additional dependencies are necessary for
the 104-dio-48e [0][1][2] and stx104 [3][4].

Due to the dependency requirements, I can take the i8254 introduction
patch through the Counter tree and provide an immutable branch that can
be merged to the GPIO and IIO trees; the 104-dio-48e patch and stx104
patch could then be picked up separately by the respective subsystem
maintainers.

[0] https://lore.kernel.org/all/05a878d340251b781387db4b6490f288e41a651c.1680543810.git.william.gray@linaro.org/
[1] https://lore.kernel.org/all/20230208105542.9459-1-william.gray@linaro.org/
[2] https://lore.kernel.org/all/cover.1679323449.git.william.gray@linaro.org/
[3] https://lore.kernel.org/all/20230318185503.341914-1-william.gray@linaro.org/
[4] https://lore.kernel.org/all/cover.1680790580.git.william.gray@linaro.org/

William Breathitt Gray (3):
  counter: i8254: Introduce the Intel 8254 interface library module
  gpio: 104-dio-48e: Add Counter/Timer support
  iio: addac: stx104: Add 8254 Counter/Timer support

 Documentation/ABI/testing/sysfs-bus-counter |  54 +++
 MAINTAINERS                                 |   7 +
 drivers/counter/Kconfig                     |  15 +
 drivers/counter/Makefile                    |   1 +
 drivers/counter/counter-sysfs.c             |   8 +-
 drivers/counter/i8254.c                     | 447 ++++++++++++++++++++
 drivers/gpio/Kconfig                        |   1 +
 drivers/gpio/gpio-104-dio-48e.c             | 127 +++++-
 drivers/iio/addac/Kconfig                   |   1 +
 drivers/iio/addac/stx104.c                  |  61 ++-
 include/linux/i8254.h                       |  21 +
 include/uapi/linux/counter.h                |   6 +
 12 files changed, 730 insertions(+), 19 deletions(-)
 create mode 100644 drivers/counter/i8254.c
 create mode 100644 include/linux/i8254.h


base-commit: 09a9639e56c01c7a00d6c0ca63f4c7c41abe075d
prerequisite-patch-id: 934c63dd47cb47e19739af076b95d3d55f5604f1
prerequisite-patch-id: 02aafdd535091da6a4ed6abbb20fb661f74af9fb
prerequisite-patch-id: cd19046150b7cff1be4ac7152198777aa960a3df
prerequisite-patch-id: bd3e3830d9ce4f3876a77483364d7190b7fdffa7
prerequisite-patch-id: 1e091c1f8f945a56cac59070221c4284306ba087
prerequisite-patch-id: c6f681fcbf7495c5ed6a596872dc4f762f22d977
prerequisite-patch-id: 239b016817624d56a4a2bddea1fda95282cb3d81
prerequisite-patch-id: 5fbfe7df44dcf5a629cd82ba8383480cb05b52d1
prerequisite-patch-id: 25a89f7312f225aaca11ef192e8d1f903a8b20e8
prerequisite-patch-id: 899b556161f417e20db8e957c5099b92c3dcb673
prerequisite-patch-id: eb09641cfb9e7caf7641ae6cb8e84e33cbb665a6

Comments

Andy Shevchenko May 20, 2023, 9:53 a.m. UTC | #1
Sun, Apr 16, 2023 at 01:36:52PM -0400, William Breathitt Gray kirjoitti:
> The Intel 8254 PIT first appeared in the early 1980s and was used
> initially in IBM PC compatibles. The popularity of the original Intel
> 825x family of chips led to many subsequent variants and clones of the
> interface in various chips and integrated circuits. Although still
> popular, interfaces compatible with the Intel 8254 PIT are nowdays
> typically found embedded in larger VLSI processing chips and FPGA
> components rather than as discrete ICs.
> 
> This patch series introduces a library to provide support for interfaces
> compatible with the venerable Intel 8254 Programmable Interval Timer
> (PIT). Modules wanting access to the i8254 library should select the
> newly introduced CONFIG_I8254 Kconfig option, and import the I8254
> symbol namespace.
> 
> Support for the i8254 is added in respective follow-up patches for the
> 104-dio-48e driver and stx104 driver whose devices feature i8254
> compatible interfaces. Several additional dependencies are necessary for
> the 104-dio-48e [0][1][2] and stx104 [3][4].
> 
> Due to the dependency requirements, I can take the i8254 introduction
> patch through the Counter tree and provide an immutable branch that can
> be merged to the GPIO and IIO trees; the 104-dio-48e patch and stx104
> patch could then be picked up separately by the respective subsystem
> maintainers.

Good job!

What I'm wondering is that. Can x86 core and others which are using that chip
utilize (some of) the functions from the library?

> [0] https://lore.kernel.org/all/05a878d340251b781387db4b6490f288e41a651c.1680543810.git.william.gray@linaro.org/
> [1] https://lore.kernel.org/all/20230208105542.9459-1-william.gray@linaro.org/
> [2] https://lore.kernel.org/all/cover.1679323449.git.william.gray@linaro.org/
> [3] https://lore.kernel.org/all/20230318185503.341914-1-william.gray@linaro.org/
> [4] https://lore.kernel.org/all/cover.1680790580.git.william.gray@linaro.org/
William Breathitt Gray May 22, 2023, 4:20 p.m. UTC | #2
On Sat, May 20, 2023 at 12:53:51PM +0300, andy.shevchenko@gmail.com wrote:
> Sun, Apr 16, 2023 at 01:36:52PM -0400, William Breathitt Gray kirjoitti:
> > The Intel 8254 PIT first appeared in the early 1980s and was used
> > initially in IBM PC compatibles. The popularity of the original Intel
> > 825x family of chips led to many subsequent variants and clones of the
> > interface in various chips and integrated circuits. Although still
> > popular, interfaces compatible with the Intel 8254 PIT are nowdays
> > typically found embedded in larger VLSI processing chips and FPGA
> > components rather than as discrete ICs.
> > 
> > This patch series introduces a library to provide support for interfaces
> > compatible with the venerable Intel 8254 Programmable Interval Timer
> > (PIT). Modules wanting access to the i8254 library should select the
> > newly introduced CONFIG_I8254 Kconfig option, and import the I8254
> > symbol namespace.
> > 
> > Support for the i8254 is added in respective follow-up patches for the
> > 104-dio-48e driver and stx104 driver whose devices feature i8254
> > compatible interfaces. Several additional dependencies are necessary for
> > the 104-dio-48e [0][1][2] and stx104 [3][4].
> > 
> > Due to the dependency requirements, I can take the i8254 introduction
> > patch through the Counter tree and provide an immutable branch that can
> > be merged to the GPIO and IIO trees; the 104-dio-48e patch and stx104
> > patch could then be picked up separately by the respective subsystem
> > maintainers.
> 
> Good job!
> 
> What I'm wondering is that. Can x86 core and others which are using that chip
> utilize (some of) the functions from the library?

Essentially we just need a regmap to register the device to the system
via devm_i8254_regmap_register(), so theoretically it would be possible
to load this driver for the integrated 8254 interface used by x86 core.
The big caveat however is that the Counter subsystem currently lacks an
in-kernel API, so registering that device would just expose the
userspace Counter sysfs and chrdev interfaces.

I suppose the interest is whether we could use the configuration
functionality of the Counter subsystem to abstract some of the hardcoded
routines and magic numbers in places like drivers/clocksource/i8253.c
and similar. Right now we wouldn't be able to do so, but perhaps in the
future if an in-kernel API is developed for the Counter subsystem then
it would be possible.

An interesting side-note about compatibility: the Intel 8253 counting
behavior differs subtly from the Intel 8254 in certain situations. For
example, suppose odd counts in Mode 3: the Intel 8253 will load the
initial count directly [0] whereas the Intel 8254 loads the initial
count minus one (an even number) [1]. This results in different maximums
and minimums: for example if the initial count is 5, the Intel 8253 will
report a maximum count of 5 and a minimum count of 2 (counting 5->4->2),
whereas the Intel 8254 will report a maximum count of 4 and a minimum
count of 0 (counting 4->2->0); same square wave is produced, but
different count values are reported.

William Breathitt Gray

[0] https://www.alldatasheet.com/datasheet-pdf/pdf/66098/INTEL/8253.html
[1] https://www.alldatasheet.com/datasheet-pdf/pdf/66099/INTEL/8254.html