Skip to contentSkip to conversation

Add Intel 8254 Counter support

PATCH Superseded William Breathitt Gray 6 participants 12 messages Apr 16, 2023 – Jun 20, 2023

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover Add Intel 8254 Counter support

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/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
[4] https://lore.kernel.org/all/[email protected]/

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

Signature · 1 line
2.39.2
#1 lore raw

PATCH 1/3 counter: i8254: Introduce the Intel 8254 interface library module

Exposes consumer library functions providing support for interfaces compatible with the venerable Intel 8254 Programmable Interval Timer (PIT).

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.

A CONFIG_I8254 Kconfig option is introduced by this patch. Modules wanting access to these i8254 library functions should select this Kconfig option, and import the I8254 symbol namespace.

---
 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 ++++++++++++++++++++
 include/linux/i8254.h                       |  21 +
 include/uapi/linux/counter.h                |   6 +
 8 files changed, 558 insertions(+), 1 deletion(-)
 create mode 100644 drivers/counter/i8254.c
 create mode 100644 include/linux/i8254.h
Documentation/ABI/testing/sysfs-bus-counter +54 -0
index ff83320b4255..6e0946e826d8 100644
@@ -60,6 +60,60 @@ Description:
 			counter does not freeze at the boundary points, but
 			counts continuously throughout.
 
+		interrupt on terminal count:
+			The output signal is initially low, and will remain low
+			until the counter reaches zero. The output signal then
+			goes high and remains high until a new preset value is
+			set.
+
+		hardware retriggerable one-shot:
+			The output signal is initially high. The output signal
+			will go low by a trigger input signal, and will remain
+			low until the counter reaches zero. The output will then
+			go high and remain high until the next trigger. A
+			trigger results in loading the counter to the preset
+			value and setting the output signal low, thus starting
+			the one-shot pulse.
+
+		rate generator:
+			The output signal is initially high. When the counter
+			has decremented to 1, the output signal goes low for one
+			clock pulse. The output signal then goes high again, the
+			counter is reloaded to the preset value, and the process
+			repeats in a periodic manner as such.
+
+		square wave mode:
+			The output signal is initially high.
+
+			If the initial count is even, the counter is decremented
+			by two on succeeding clock pulses. When the count
+			expires, the output signal changes value and the
+			counter is reloaded to the preset value. The process
+			repeats in periodic manner as such.
+
+			If the initial count is odd, the initial count minus one
+			(an even number) is loaded and then is decremented by
+			two on succeeding clock pulses. One clock pulse after
+			the count expires, the output signal goes low and the
+			counter is reloaded to the preset value minus one.
+			Succeeding clock pulses decrement the count by two. When
+			the count expires, the output goes high again and the
+			counter is reloaded to the preset value minus one. The
+			process repeats in a periodic manner as such.
+
+		software triggered strobe:
+			The output signal is initially high. When the count
+			expires, the output will go low for one clock pulse and
+			then go high again. The counting sequence is "triggered"
+			by setting the preset value.
+
+		hardware triggered strobe:
+			The output signal is initially high. Counting is started
+			by a trigger input signal. When the count expires, the
+			output signal will go low for one clock pulse and then
+			go high again. A trigger results in loading the counter
+			to the preset value.
+
 What:		/sys/bus/counter/devices/counterX/countY/count_mode_available
 What:		/sys/bus/counter/devices/counterX/countY/error_noise_available
 What:		/sys/bus/counter/devices/counterX/countY/function_available
MAINTAINERS +7 -0
index 90abe83c02f3..ac170417e1c9 100644
@@ -10170,6 +10170,13 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/video/fbdev/i810/
 
+INTEL 8254 COUNTER DRIVER
+M:	William Breathitt Gray <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/counter/i8254.c
+F:	include/linux/i8254.h
+
 INTEL 8255 GPIO DRIVER
 M:	William Breathitt Gray <[email protected]>
 L:	[email protected]
drivers/counter/Kconfig +15 -0
index b5ba8fb02cf7..5a711811819b 100644
@@ -10,6 +10,21 @@ menuconfig COUNTER
 	  interface. You only need to enable this, if you also want to enable
 	  one or more of the counter device drivers below.
 
+config I8254
+	tristate
+	select COUNTER
+	select REGMAP
+	help
+	  Enables support for the i8254 interface library functions. The i8254
+	  interface library provides functions to facilitate communication with
+	  interfaces compatible with the venerable Intel 8254 Programmable
+	  Interval Timer (PIT). The Intel 825x family of chips was first
+	  released in the early 1980s but compatible interfaces are nowadays
+	  typically found embedded in larger VLSI processing chips and FPGA
+	  components.
+
+	  If built as a module its name will be i8254.
+
 if COUNTER
 
 config 104_QUAD_8
drivers/counter/Makefile +1 -0
index b9a369e0d4fc..395c17ddc37a 100644
@@ -6,6 +6,7 @@
 obj-$(CONFIG_COUNTER) += counter.o
 counter-y := counter-core.o counter-sysfs.o counter-chrdev.o
 
+obj-$(CONFIG_I8254)		+= i8254.o
 obj-$(CONFIG_104_QUAD_8)	+= 104-quad-8.o
 obj-$(CONFIG_INTERRUPT_CNT)		+= interrupt-cnt.o
 obj-$(CONFIG_STM32_TIMER_CNT)	+= stm32-timer-cnt.o
drivers/counter/counter-sysfs.c +7 -1
index b9efe66f9f8d..42c523343d32 100644
@@ -88,7 +88,13 @@ static const char *const counter_count_mode_str[] = {
 	[COUNTER_COUNT_MODE_NORMAL] = "normal",
 	[COUNTER_COUNT_MODE_RANGE_LIMIT] = "range limit",
 	[COUNTER_COUNT_MODE_NON_RECYCLE] = "non-recycle",
-	[COUNTER_COUNT_MODE_MODULO_N] = "modulo-n"
+	[COUNTER_COUNT_MODE_MODULO_N] = "modulo-n",
+	[COUNTER_COUNT_MODE_INTERRUPT_ON_TERMINAL_COUNT] = "interrupt on terminal count",
+	[COUNTER_COUNT_MODE_HARDWARE_RETRIGGERABLE_ONESHOT] = "hardware retriggerable one-shot",
+	[COUNTER_COUNT_MODE_RATE_GENERATOR] = "rate generator",
+	[COUNTER_COUNT_MODE_SQUARE_WAVE_MODE] = "square wave mode",
+	[COUNTER_COUNT_MODE_SOFTWARE_TRIGGERED_STROBE] = "software triggered strobe",
+	[COUNTER_COUNT_MODE_HARDWARE_TRIGGERED_STROBE] = "hardware triggered strobe",
 };
 
 static const char *const counter_signal_polarity_str[] = {
drivers/counter/i8254.c new file +447 -0

447 lines not on this page · raw message

include/linux/i8254.h new file +21 -0
new file mode 100644
index 000000000000..a675c309232b
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) William Breathitt Gray */
+#ifndef _I8254_H_
+#define _I8254_H_
+
+struct device;
+struct regmap;
+
+/**
+ * struct i8254_regmap_config - Configuration for the register map of an i8254
+ * @parent:	parent device
+ * @map:	regmap for the i8254
+ */
+struct i8254_regmap_config {
+	struct device *parent;
+	struct regmap *map;
+};
+
+int devm_i8254_regmap_register(struct device *dev, const struct i8254_regmap_config *config);
+
+#endif /* _I8254_H_ */
include/uapi/linux/counter.h +6 -0
index 8ab12d731e3b..fc248ef00e86 100644
@@ -127,6 +127,12 @@ enum counter_count_mode {
 	COUNTER_COUNT_MODE_RANGE_LIMIT,
 	COUNTER_COUNT_MODE_NON_RECYCLE,
 	COUNTER_COUNT_MODE_MODULO_N,
+	COUNTER_COUNT_MODE_INTERRUPT_ON_TERMINAL_COUNT,
+	COUNTER_COUNT_MODE_HARDWARE_RETRIGGERABLE_ONESHOT,
+	COUNTER_COUNT_MODE_RATE_GENERATOR,
+	COUNTER_COUNT_MODE_SQUARE_WAVE_MODE,
+	COUNTER_COUNT_MODE_SOFTWARE_TRIGGERED_STROBE,
+	COUNTER_COUNT_MODE_HARDWARE_TRIGGERED_STROBE,
 };
 
 /* Count function values */
Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH 1/3] counter: i8254: Introduce the Intel 8254 interface library module

Quoted 12 lines · William Breathitt Gray

Exposes consumer library functions providing support for interfaces compatible with the venerable Intel 8254 Programmable Interval Timer (PIT).

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.

Quoted 5 lines

A CONFIG_I8254 Kconfig option is introduced by this patch. Modules wanting access to these i8254 library functions should select this Kconfig option, and import the I8254 symbol namespace.

I've queued this patch to the counter-next branch of my Counter tree.

Jonathan, Bart, I've created an immutable branch with just this patch for you to pull which should allow you each to merge the other patch in this patchset for your respective tree.

The following changes since commit ac9a78681b921877518763ba0e89202254349d1b:

Linux 6.4-rc1 (2023-05-07 13:34:35 -0700)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/wbg/counter.git tags/i8254

for you to fetch changes up to b923ba2c0829a1a22151139309b4ae5d47a99d34:

counter: i8254: Introduce the Intel 8254 interface library module (2023-06-08 10:14:10 -0400)

----------------------------------------------------------------
counter: i8254: Introduce the Intel 8254 interface library module

This exposes consumer library functions providing support for interfaces compatible with the venerable Intel 8254 Programmable Interval Timer.

----------------------------------------------------------------
William Breathitt Gray (1):
counter: i8254: Introduce the Intel 8254 interface library module

 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 ++++++++++++++++++++++++++++
 include/linux/i8254.h                       |  21 ++
 include/uapi/linux/counter.h                |   6 +
 8 files changed, 558 insertions(+), 1 deletion(-)
 create mode 100644 drivers/counter/i8254.c
 create mode 100644 include/linux/i8254.h

Sincerely,

William Breathitt Gray

#3 lore raw

Re: [PATCH 1/3] counter: i8254: Introduce the Intel 8254 interface library module

Hi

Quoted 17 lines · William Breathitt Gray
Quoted 16 lines · William Breathitt Gray

Exposes consumer library functions providing support for interfaces compatible with the venerable Intel 8254 Programmable Interval Timer (PIT).

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.

A CONFIG_I8254 Kconfig option is introduced by this patch. Modules wanting access to these i8254 library functions should select this Kconfig option, and import the I8254 symbol namespace.

Quoted 8 lines
Quoted 1 line

I've queued this patch to the counter-next branch of my Counter tree.

Jonathan, Bart, I've created an immutable branch with just this patch for you to pull which should allow you each to merge the other patch in this patchset for your respective tree.

I noticed this patch cause in linux-next "Counter support" submenu to disappear and its menu entries are listed directly in "Device Drivers" menu.

Then I wonder why the CONFIG_I8254 has the help text defined since drivers should select it.

Or was the idea something like below?

drivers/counter/Kconfig +0 -0
index bca21df51168..80631b5b0fc6 100644
@@ -10,9 +10,10 @@ menuconfig COUNTER
          interface. You only need to enable this, if you also want to 

enable
one or more of the counter device drivers below.

+if COUNTER
+
config I8254

-       tristate
-       select COUNTER
+       tristate "i8254 interface library"

select REGMAP
help
Enables support for the i8254 interface library functions.
The i8254
@@ -25,8 +26,6 @@ config I8254

If built as a module its name will be i8254.

-if COUNTER
-
config 104_QUAD_8
tristate "ACCES 104-QUAD-8 driver"
depends on (PC104 && X86) || COMPILE_TEST

#4 lore raw

Re: [PATCH 1/3] counter: i8254: Introduce the Intel 8254 interface library module

Quoted 56 lines · Jarkko Nikula

Hi

Quoted 17 lines · William Breathitt Gray
Quoted 16 lines · William Breathitt Gray

Exposes consumer library functions providing support for interfaces compatible with the venerable Intel 8254 Programmable Interval Timer (PIT).

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.

A CONFIG_I8254 Kconfig option is introduced by this patch. Modules wanting access to these i8254 library functions should select this Kconfig option, and import the I8254 symbol namespace.

Quoted 8 lines
Quoted 1 line

I've queued this patch to the counter-next branch of my Counter tree.

Jonathan, Bart, I've created an immutable branch with just this patch for you to pull which should allow you each to merge the other patch in this patchset for your respective tree.

I noticed this patch cause in linux-next "Counter support" submenu to disappear and its menu entries are listed directly in "Device Drivers" menu.

Then I wonder why the CONFIG_I8254 has the help text defined since drivers should select it.

Or was the idea something like below?

drivers/counter/Kconfig +0 -0
index bca21df51168..80631b5b0fc6 100644
@@ -10,9 +10,10 @@ menuconfig COUNTER
          interface. You only need to enable this, if you also want to

enable
one or more of the counter device drivers below.

drivers/counter/Kconfig +3 -2
+if COUNTER
+
 config I8254
-       tristate
-       select COUNTER
+       tristate "i8254 interface library"
        select REGMAP
        help
          Enables support for the i8254 interface library functions. The

i8254

drivers/counter/Kconfig config I8254 · line 31

Quoted 8 lines
drivers/counter/Kconfig +0 -2
@@ -25,8 +26,6 @@ config I8254
 
          If built as a module its name will be i8254.
 
-if COUNTER
-
 config 104_QUAD_8
        tristate "ACCES 104-QUAD-8 driver"
        depends on (PC104 && X86) || COMPILE_TEST

Hi Jarkko,

Thank you for pointing that out, the config I8254 entry should have been added above the menuconfig COUNTER entry instead of below it; if you move it you should notice the "Counter support" submenu items go back to normal. The intention is for consumer drivers to select I8254 when they use the library. The I8254 module doesn't do anything on its own so that's why it's hidden in the menu (the help description is there for the sake of reviewers). I'll submit a patch soon fixing this.

Thanks,

William Breathitt Gray

#5 lore raw

PATCH 2/3 gpio: 104-dio-48e: Add Counter/Timer support

In reply to William Breathitt Gray

The 104-DIO-48E features an 8254 Counter/Timer chip providing three counter/timers which can be used for frequency measurement, frequency output, pulse width modulation, pulse width measurement, event count, etc. The counter/timers use the same addresses as PPI 0 (addresses 0x0 to 0x3), so a raw_spinlock_t is used to synchronize operations between the two regmap mappings to prevent clobbering.

---
 drivers/gpio/Kconfig            |   1 +
 drivers/gpio/gpio-104-dio-48e.c | 127 ++++++++++++++++++++++++++++----
 2 files changed, 112 insertions(+), 16 deletions(-)
drivers/gpio/Kconfig +1 -0
index badbe0582318..1fcc1245f954 100644
@@ -840,6 +840,7 @@ config GPIO_104_DIO_48E
 	select REGMAP_IRQ
 	select GPIOLIB_IRQCHIP
 	select GPIO_I8255
+	select I8254
 	help
 	  Enables GPIO support for the ACCES 104-DIO-48E series (104-DIO-48E,
 	  104-DIO-24E). The base port addresses for the devices may be
drivers/gpio/gpio-104-dio-48e.c +111 -16

197 lines not on this page · raw message

Signature · 1 line
2.39.2
#6 lore raw

Re: [PATCH 2/3] gpio: 104-dio-48e: Add Counter/Timer support

Quoted 9 lines · William Breathitt Gray

The 104-DIO-48E features an 8254 Counter/Timer chip providing three counter/timers which can be used for frequency measurement, frequency output, pulse width modulation, pulse width measurement, event count, etc. The counter/timers use the same addresses as PPI 0 (addresses 0x0 to 0x3), so a raw_spinlock_t is used to synchronize operations between the two regmap mappings to prevent clobbering.

Looks good to me. Let me know when you have an immutable tag to pull.

Bart

Reviewed-by on v1 2/3
#7 lore raw

Re: [PATCH 2/3] gpio: 104-dio-48e: Add Counter/Timer support

In reply to William Breathitt Gray
Quoted 8 lines · William Breathitt Gray

The 104-DIO-48E features an 8254 Counter/Timer chip providing three counter/timers which can be used for frequency measurement, frequency output, pulse width modulation, pulse width measurement, event count, etc. The counter/timers use the same addresses as PPI 0 (addresses 0x0 to 0x3), so a raw_spinlock_t is used to synchronize operations between the two regmap mappings to prevent clobbering.

Very interesting development here.

Yours,
Linus Walleij

#8 lore raw

Re: [PATCH 2/3] gpio: 104-dio-48e: Add Counter/Timer support

Quoted 10 lines · Linus Walleij
Quoted 7 lines · William Breathitt Gray

The 104-DIO-48E features an 8254 Counter/Timer chip providing three counter/timers which can be used for frequency measurement, frequency output, pulse width modulation, pulse width measurement, event count, etc. The counter/timers use the same addresses as PPI 0 (addresses 0x0 to 0x3), so a raw_spinlock_t is used to synchronize operations between the two regmap mappings to prevent clobbering.

Quoted 7 lines
Quoted 1 line

Very interesting development here.

Yours,
Linus Walleij

With this patch, we should now have complete support for every feature available on this device. A nice milestone as well after first introducing basic GPIO support for the ACCES 104-DIO-48E in 2016.

Given that there is also Intel 8255 support, it would be fun to route back one of the device's GPIO outputs into the Intel 8254 timer gate and hook up a simple speaker; we could get some nice beep generation going and party like it's 1989! B-)

William Breathitt Gray

#9 lore raw

PATCH 3/3 iio: addac: stx104: Add 8254 Counter/Timer support

In reply to William Breathitt Gray

The STX104 features an 8254 Counter/Timer chip providing three counter/timers which can be used for frequency measurement, frequency output, pulse width modulation, pulse width measurement, event count, etc. The STX104 provides a register bank selection to bank select between the 8254 Bank and the Indexed Register Array Bank; the Indexed Register Array is not utilized by this driver, so the 8254 Bank is selected unconditionally.

---
 drivers/iio/addac/Kconfig  |  1 +
 drivers/iio/addac/stx104.c | 61 ++++++++++++++++++++++++++++++++++++--
 2 files changed, 60 insertions(+), 2 deletions(-)
drivers/iio/addac/Kconfig +1 -0
index 877f9124803c..b2623881f0ec 100644
@@ -38,6 +38,7 @@ config STX104
 	select REGMAP_MMIO
 	select GPIOLIB
 	select GPIO_REGMAP
+	select I8254
 	help
 	  Say yes here to build support for the Apex Embedded Systems STX104
 	  integrated analog PC/104 card.
drivers/iio/addac/stx104.c +59 -2

118 lines not on this page · raw message

Signature · 1 line
2.39.2
#10 lore raw
In reply to William Breathitt Gray

Sun, Apr 16, 2023 at 01:36:52PM -0400, William Breathitt Gray kirjoitti:

Quoted 19 lines

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].

Quoted 5 lines

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?

Quoted 5 lines

[0] https://lore.kernel.org/all/05a878d340251b781387db4b6490f288e41a651c.1680543810.git.william.gray@linaro.org/
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
[4] https://lore.kernel.org/all/[email protected]/

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#11 lore raw
Quoted 26 lines · On Sat, May 20, 2023 at 12:53:51PM +0300, [email protected] wrote:

Sun, Apr 16, 2023 at 01:36:52PM -0400, William Breathitt Gray kirjoitti:

Quoted 19 lines

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].

Quoted 5 lines

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.

Quoted 4 lines

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