Skip to contentSkip to conversation

Driver for Apple Z2 touchscreens.

PATCH Superseded Sasha Finkelstein 4 participants 11 messages Jan 15, 2025 – Jan 18, 2025

Subsystems (4)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover Driver for Apple Z2 touchscreens.

Hi.

This series adds support for Apple touchscreens using the Z2 protocol. Those are used as the primary touchscreen on mobile Apple devices, and for the touchbar on laptops using the M-series chips. (T1/T2 laptops have a coprocessor in charge of speaking Z2 to the touchbar).

Originally sent as a RFC at https://lore.kernel.org/all/[email protected]/
The changes since then mostly address the review feedback, but also
add another machine that has this specific controller.

---
Changes in v4:
- Dropped another allocation, other fixes.
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Tx/Rx buffers used in interrupt handler are now allocated in probe and reused
- Other various style fixes
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- In a separate patch, fixed an issue that prevented the SPI controller from using GPIO CS, and as such, moved the hardware quirk to there
- Went back to uploading the firmware in probe() instad of open()
- Other changes addressing the review feedback
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Sasha Finkelstein (4):
dt-bindings: input: touchscreen: Add Z2 controller
input: apple_z2: Add a driver for Apple Z2 touchscreens
arm64: dts: apple: Add touchbar digitizer nodes
MAINTAINERS: Add entries for Apple Z2 touchscreen driver

 .../input/touchscreen/apple,z2-multitouch.yaml     |  70 ++++
 MAINTAINERS                                        |   2 +
 arch/arm64/boot/dts/apple/t8103-j293.dts           |  27 ++
 arch/arm64/boot/dts/apple/t8103.dtsi               |  19 +
 arch/arm64/boot/dts/apple/t8112-j493.dts           |  23 ++
 arch/arm64/boot/dts/apple/t8112.dtsi               |  14 +
 drivers/input/touchscreen/Kconfig                  |  13 +
 drivers/input/touchscreen/Makefile                 |   1 +
 drivers/input/touchscreen/apple_z2.c               | 454 +++++++++++++++++++++
 9 files changed, 623 insertions(+)

---
base-commit: b62cef9a5c673f1b8083159f5dc03c1c5daced2f
change-id: 20241124-z2-c012b528ea0d

#1 lore raw

PATCH v4 1/4 dt-bindings: input: touchscreen: Add Z2 controller

From: Sasha Finkelstein <[email protected]>

Add bindings for touchscreen controllers attached using the Z2 protocol. Those are present in most Apple devices.

---
 .../input/touchscreen/apple,z2-multitouch.yaml     | 70 ++++++++++++++++++++++
 1 file changed, 70 insertions(+)
Documentation/devicetree/bindings/input/touchscreen/apple,z2-multitouch.yaml new file +70 -0
new file mode 100644
index 0000000000000000000000000000000000000000..402ca6bffd3473a1a889ced7890e9836e6a76e45
@@ -0,0 +1,70 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/input/touchscreen/apple,z2-multitouch.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Apple touchscreens attached using the Z2 protocol
+
+maintainers:
+  - Sasha Finkelstein <[email protected]>
+
+description: A series of touschscreen controllers used in Apple products
+
+allOf:
+  - $ref: touchscreen.yaml#
+  - $ref: /schemas/spi/spi-peripheral-props.yaml#
+
+properties:
+  compatible:
+    enum:
+      - apple,j293-touchbar
+      - apple,j493-touchbar
+
+  interrupts:
+    maxItems: 1
+
+  reset-gpios:
+    maxItems: 1
+
+  firmware-name:
+    maxItems: 1
+
+  apple,z2-cal-blob:
+    $ref: /schemas/types.yaml#/definitions/uint8-array
+    maxItems: 4096
+    description:
+      Calibration blob supplied by the bootloader
+
+required:
+  - compatible
+  - interrupts
+  - reset-gpios
+  - firmware-name
+  - touchscreen-size-x
+  - touchscreen-size-y
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    spi {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        touchscreen@0 {
+            compatible = "apple,j293-touchbar";
+            reg = <0>;
+            spi-max-frequency = <11500000>;
+            reset-gpios = <&pinctrl_ap 139 GPIO_ACTIVE_LOW>;
+            interrupts-extended = <&pinctrl_ap 194 IRQ_TYPE_EDGE_FALLING>;
+            firmware-name = "apple/dfrmtfw-j293.bin";
+            touchscreen-size-x = <23045>;
+            touchscreen-size-y = <640>;
+        };
+    };
+
+...
Signature · 1 line
2.48.0
#2 lore raw

PATCH v4 2/4 input: apple_z2: Add a driver for Apple Z2 touchscreens

In reply to Sasha Finkelstein

From: Sasha Finkelstein <[email protected]>

Adds a driver for Apple touchscreens using the Z2 protocol.

---
 drivers/input/touchscreen/Kconfig    |  13 +
 drivers/input/touchscreen/Makefile   |   1 +
 drivers/input/touchscreen/apple_z2.c | 454 +++++++++++++++++++++++++++++++++++
 3 files changed, 468 insertions(+)
drivers/input/touchscreen/Kconfig +13 -0
index 1a03de7fcfa66c0f60768be17d776a79e36e570e..6c885cc58f323b3628538d41460248f8ab1dbf7d 100644
@@ -103,6 +103,19 @@ config TOUCHSCREEN_ADC
 	  To compile this driver as a module, choose M here: the
 	  module will be called resistive-adc-touch.ko.
 
+config TOUCHSCREEN_APPLE_Z2
+	tristate "Apple Z2 touchscreens"
+	default ARCH_APPLE
+	depends on SPI
+	help
+	  Say Y here if you have an Apple device with
+	  a touchscreen or a touchbar.
+
+	  If unsure, say N.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called apple_z2.
+
 config TOUCHSCREEN_AR1021_I2C
 	tristate "Microchip AR1020/1021 i2c touchscreen"
 	depends on I2C && OF
drivers/input/touchscreen/Makefile +1 -0
index 82bc837ca01e2ee18c5e9c578765d55ef9fab6d4..97a025c6a3770fb80255246eb63c11688ebd79eb 100644
@@ -15,6 +15,7 @@ obj-$(CONFIG_TOUCHSCREEN_AD7879_I2C)	+= ad7879-i2c.o
 obj-$(CONFIG_TOUCHSCREEN_AD7879_SPI)	+= ad7879-spi.o
 obj-$(CONFIG_TOUCHSCREEN_ADC)		+= resistive-adc-touch.o
 obj-$(CONFIG_TOUCHSCREEN_ADS7846)	+= ads7846.o
+obj-$(CONFIG_TOUCHSCREEN_APPLE_Z2)	+= apple_z2.o
 obj-$(CONFIG_TOUCHSCREEN_AR1021_I2C)	+= ar1021_i2c.o
 obj-$(CONFIG_TOUCHSCREEN_ATMEL_MXT)	+= atmel_mxt_ts.o
 obj-$(CONFIG_TOUCHSCREEN_AUO_PIXCIR)	+= auo-pixcir-ts.o
drivers/input/touchscreen/apple_z2.c new file +454 -0

454 lines not on this page · raw message

Signature · 1 line
2.48.0
#3 lore raw

Re: [PATCH v4 2/4] input: apple_z2: Add a driver for Apple Z2 touchscreens

Le 15/01/2025 à 23:46, Sasha Finkelstein via B4 Relay a écrit :

Quoted 4 lines

From: Sasha Finkelstein <[email protected]>

Adds a driver for Apple touchscreens using the Z2 protocol.

...

Quoted 57 lines
drivers/input/touchscreen/apple_z2.c new file +57 -0
+static int apple_z2_upload_firmware(struct apple_z2 *z2)
+{
+	const struct apple_z2_fw_hdr *fw_hdr;
+	size_t fw_idx = sizeof(struct apple_z2_fw_hdr);
+	int error;
+	u32 load_cmd;
+	u32 size;
+	u32 address;
+	char *data;
+	bool init;
+	size_t cal_size;
+
+	const struct firmware *fw __free(firmware) = NULL;
+	error = request_firmware(&fw, z2->fw_name, &z2->spidev->dev);
+	if (error) {
+		dev_err(&z2->spidev->dev, "unable to load firmware");
+		return error;
+	}
+
+	fw_hdr = (const struct apple_z2_fw_hdr *)fw->data;
+	if (le32_to_cpu(fw_hdr->magic) != APPLE_Z2_FW_MAGIC || le32_to_cpu(fw_hdr->version) != 1) {
+		dev_err(&z2->spidev->dev, "invalid firmware header");
+		return -EINVAL;
+	}
+
+	/*
+	 * This will interrupt the upload half-way if the file is malformed
+	 * As the device has no non-volatile storage to corrupt, and gets reset
+	 * on boot anyway, this is fine.
+	 */
+	while (fw_idx < fw->size) {
+		if (fw->size - fw_idx < 8) {
+			dev_err(&z2->spidev->dev, "firmware malformed");
+			return -EINVAL;
+		}
+
+		load_cmd = le32_to_cpu(*(__le32 *)(fw->data + fw_idx));
+		fw_idx += sizeof(u32);
+		if (load_cmd == LOAD_COMMAND_INIT_PAYLOAD || load_cmd == LOAD_COMMAND_SEND_BLOB) {
+			size = le32_to_cpu(*(__le32 *)(fw->data + fw_idx));
+			fw_idx += sizeof(u32);
+			if (fw->size - fw_idx < size) {
+				dev_err(&z2->spidev->dev, "firmware malformed");
+				return -EINVAL;
+			}
+			init = load_cmd == LOAD_COMMAND_INIT_PAYLOAD;
+			error = apple_z2_send_firmware_blob(z2, fw->data + fw_idx,
+							    size, init);
+			if (error)
+				return error;
+			fw_idx += size;
+		} else if (load_cmd == LOAD_COMMAND_SEND_CALIBRATION) {
+			address = le32_to_cpu(*(u32 *)(fw->data + fw_idx));
+			fw_idx += sizeof(u32);
+			cal_size = device_property_count_u8(&z2->spidev->dev, CAL_PROP_NAME);
+			if (cal_size != 0) {
+				size = cal_size + sizeof(struct apple_z2_hbpp_blob_hdr) + 4;

drivers/input/touchscreen/apple_z2.c line 296

Quoted 10 lines
drivers/input/touchscreen/apple_z2.c new file +10 -0
+				data = kzalloc(size, GFP_KERNEL);
+				error = apple_z2_build_cal_blob(z2, address, cal_size, data);
+				if (!error)
+					error = apple_z2_send_firmware_blob(z2, data, size, 16);
+				kfree(data);
+				if (error)
+					return error;
+			}
+		} else {
+			dev_err(&z2->spidev->dev, "firmware malformed");

Missing \n.

Quoted 11 lines
drivers/input/touchscreen/apple_z2.c new file +11 -0
+			return -EINVAL;
+		}
+		if (fw_idx % 4 != 0)
+			fw_idx += 4 - (fw_idx % 4);
+	}
+
+
+	z2->booted = true;
+	apple_z2_read_packet(z2);
+	return 0;
+}

...

drivers/input/touchscreen/apple_z2.c line 340

Quoted 12 lines
drivers/input/touchscreen/apple_z2.c new file +12 -0
+static int apple_z2_probe(struct spi_device *spi)
+{
+	struct device *dev = &spi->dev;
+	struct apple_z2 *z2;
+	int error;
+
+	z2 = devm_kzalloc(dev, sizeof(*z2), GFP_KERNEL);
+	if (!z2)
+		return -ENOMEM;
+
+	z2->tx_buf = devm_kzalloc(dev, sizeof(struct apple_z2_read_interrupt_cmd), GFP_KERNEL);
+	z2->rx_buf = devm_kzalloc(dev, 4096, GFP_KERNEL);

This will allocate 8192 bytes because of the way the allocator works.
It needs around 40 bytes for the devm stuff + 4096 requested. So rounding rules will allocate 8192 bytes.

So either you could allocate "for free" much more space, or you could allocate (and document...)

	z2->rx_buf = devm_kzalloc(dev, 4096 - sizeof(struct devres), GFP_KERNEL);

or have an explicit devm_add_action_or_reset() that would require less memory, but would add some LoC.

See https://elixir.bootlin.com/linux/v6.13-rc3/source/drivers/base/devres.c#L97

Quoted 7 lines
drivers/input/touchscreen/apple_z2.c new file +7 -0
+	if (!z2->tx_buf || !z2->rx_buf)
+		return -ENOMEM;
+
+	z2->spidev = spi;
+	init_completion(&z2->boot_irq);
+	spi_set_drvdata(spi, z2);
+

drivers/input/touchscreen/apple_z2.c line 357

Quoted 10 lines
drivers/input/touchscreen/apple_z2.c new file +10 -0
+	/* Reset the device on boot */
+	z2->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
+	if (IS_ERR(z2->reset_gpio))
+		return dev_err_probe(dev, PTR_ERR(z2->reset_gpio), "unable to get reset");
+
+	error = devm_request_threaded_irq(dev, z2->spidev->irq, NULL,
+					apple_z2_irq, IRQF_ONESHOT | IRQF_NO_AUTOEN,
+					"apple-z2-irq", spi);
+	if (error)
+		return dev_err_probe(dev, z2->spidev->irq, "unable to request irq");

Missing \n.

s/z2->spidev->irq/error/ ?

or maybe:
return dev_err_probe(dev, error, "unable to request irq %d\n",
z2->spidev->irq);

drivers/input/touchscreen/apple_z2.c line 361

Quoted 4 lines
drivers/input/touchscreen/apple_z2.c new file +4 -0
+
+	error = device_property_read_string(dev, "firmware-name", &z2->fw_name);
+	if (error)
+		return dev_err_probe(dev, error, "unable to get firmware name");

Missing \n.

Quoted 11 lines
drivers/input/touchscreen/apple_z2.c new file +11 -0
+
+	z2->input_dev = devm_input_allocate_device(dev);
+	if (!z2->input_dev)
+		return -ENOMEM;
+	z2->input_dev->name = (char *)spi_get_device_id(spi)->driver_data;
+	z2->input_dev->phys = "apple_z2";
+	z2->input_dev->id.bustype = BUS_SPI;
+
+	/* Allocate the axes before setting from DT */
+	input_set_abs_params(z2->input_dev, ABS_MT_POSITION_X, 0, 0, 0, 0);
+	input_set_abs_params(z2->input_dev, ABS_MT_POSITION_Y, 0, 0, 0, 0);

drivers/input/touchscreen/apple_z2.c line 382

Quoted 10 lines
drivers/input/touchscreen/apple_z2.c new file +10 -0
+	touchscreen_parse_properties(z2->input_dev, true, &z2->props);
+	input_abs_set_res(z2->input_dev, ABS_MT_POSITION_X, 100);
+	input_abs_set_res(z2->input_dev, ABS_MT_POSITION_Y, 100);
+	input_set_abs_params(z2->input_dev, ABS_MT_WIDTH_MAJOR, 0, 65535, 0, 0);
+	input_set_abs_params(z2->input_dev, ABS_MT_WIDTH_MINOR, 0, 65535, 0, 0);
+	input_set_abs_params(z2->input_dev, ABS_MT_TOUCH_MAJOR, 0, 65535, 0, 0);
+	input_set_abs_params(z2->input_dev, ABS_MT_TOUCH_MINOR, 0, 65535, 0, 0);
+	input_set_abs_params(z2->input_dev, ABS_MT_ORIENTATION, -32768, 32767, 0, 0);
+
+	input_set_drvdata(z2->input_dev, z2);

Is it needed? (there is no input_get_drvdata())

drivers/input/touchscreen/apple_z2.c line 386

Quoted 4 lines
drivers/input/touchscreen/apple_z2.c new file +4 -0
+
+	error = input_mt_init_slots(z2->input_dev, 256, INPUT_MT_DIRECT);
+	if (error)
+		return dev_err_probe(dev, error, "unable to initialize multitouch slots");

Missing \n.

drivers/input/touchscreen/apple_z2.c line 390

Quoted 4 lines
drivers/input/touchscreen/apple_z2.c new file +4 -0
+
+	error = input_register_device(z2->input_dev);
+	if (error)
+		return dev_err_probe(dev, error, "unable to register input device");

Missing \n.

drivers/input/touchscreen/apple_z2.c line 397

Quoted 7 lines
drivers/input/touchscreen/apple_z2.c new file +7 -0
+
+	/* Wait for device reset to finish */
+	usleep_range(5000, 10000);
+	error = apple_z2_boot(z2);
+	if (error)
+		return error;
+	return 0;

Nitpick: These 4 lines could be just:

	return apple_z2_boot(z2);
Quoted 1 line

+}

...

drivers/input/touchscreen/apple_z2.c line 427

Quoted 6 lines
drivers/input/touchscreen/apple_z2.c new file +6 -0
+static DEFINE_SIMPLE_DEV_PM_OPS(apple_z2_pm, apple_z2_suspend, apple_z2_resume);
+
+static const struct of_device_id apple_z2_of_match[] = {
+	{ .compatible = "apple,j293-touchbar" },
+	{ .compatible = "apple,j493-touchbar" },
+	{},

Nitpick: Ending comma is not needed after a terminator.

drivers/input/touchscreen/apple_z2.c line 436

Quoted 9 lines
drivers/input/touchscreen/apple_z2.c new file +9 -0
+};
+MODULE_DEVICE_TABLE(of, apple_z2_of_match);
+
+static struct spi_device_id apple_z2_of_id[] = {
+	{ .name = "j293-touchbar", .driver_data = (kernel_ulong_t)"MacBookPro17,1 Touch Bar" },
+	{ .name = "j493-touchbar", .driver_data = (kernel_ulong_t)"Mac14,7 Touch Bar" },
+	{}
+};
+MODULE_DEVICE_TABLE(spi, apple_z2_of_id);

...

CJ

maintainer
#4 lore raw

Re: [PATCH v4 2/4] input: apple_z2: Add a driver for Apple Z2 touchscreens

Quoted 11 lines · Christophe JAILLET

Le 15/01/2025 à 23:46, Sasha Finkelstein via B4 Relay a écrit :

drivers/input/touchscreen/apple_z2.c line 397

Quoted 7 lines
drivers/input/touchscreen/apple_z2.c new file +7 -0
+
+	/* Wait for device reset to finish */
+	usleep_range(5000, 10000);
+	error = apple_z2_boot(z2);
+	if (error)
+		return error;
+	return 0;

Nitpick: These 4 lines could be just:

Quoted 1 line
	return apple_z2_boot(z2);

The current form is actually my preference - if a function has multiple points of failure then do

	error = action(...);
	if (error)
		return error;

everywhere with final "return 0;" at the end. This way it is easier to rearrange code if needed.

Thanks.

Signature · 1 line
Dmitry
#5 lore raw

Re: [PATCH v4 2/4] input: apple_z2: Add a driver for Apple Z2 touchscreens

In reply to Christophe JAILLET
Quoted 17 lines
Quoted 11 lines
drivers/input/touchscreen/apple_z2.c new file +11 -0
+static int apple_z2_probe(struct spi_device *spi)
+{
+    struct device *dev = &spi->dev;
+    struct apple_z2 *z2;
+    int error;
+
+    z2 = devm_kzalloc(dev, sizeof(*z2), GFP_KERNEL);
+    if (!z2)
+        return -ENOMEM;
+
+    z2->tx_buf = devm_kzalloc(dev, sizeof(struct 
Quoted 2 lines

apple_z2_read_interrupt_cmd), GFP_KERNEL);
+    z2->rx_buf = devm_kzalloc(dev, 4096, GFP_KERNEL);

This will allocate 8192 bytes because of the way the allocator works.
It needs around 40 bytes for the devm stuff + 4096 requested. So rounding rules will allocate 8192 bytes.

Quoted 6 lines

So either you could allocate "for free" much more space, or you could allocate (and document...)
    z2->rx_buf = devm_kzalloc(dev, 4096 - sizeof(struct devres),
GFP_KERNEL);

or have an explicit devm_add_action_or_reset() that would require less memory, but would add some LoC.

or leave it as-is, of course ;-)

Quoted 3 lines

See https://elixir.bootlin.com/linux/v6.13-rc3/source/drivers/base/ devres.c#L97

#6 lore raw

Re: [PATCH v4 2/4] input: apple_z2: Add a driver for Apple Z2 touchscreens

Quoted 14 lines · Christophe JAILLET
Quoted 14 lines
Quoted 4 lines

+ z2->tx_buf = devm_kzalloc(dev, sizeof(struct
apple_z2_read_interrupt_cmd), GFP_KERNEL);
+ z2->rx_buf = devm_kzalloc(dev, 4096, GFP_KERNEL);

This will allocate 8192 bytes because of the way the allocator works. It needs around 40 bytes for the devm stuff + 4096 requested. So rounding rules will allocate 8192 bytes.

So either you could allocate "for free" much more space, or you could allocate (and document...)

     z2->rx_buf = devm_kzalloc(dev, 4096 - sizeof(struct devres),

GFP_KERNEL);

Quoted 10 lines
Quoted 3 lines

or have an explicit devm_add_action_or_reset() that would require less memory, but would add some LoC.

or leave it as-is, of course ;-)

Quoted 4 lines

See https://elixir.bootlin.com/linux/v6.13-rc3/source/drivers/base/
devres.c#L97

The precise size does not matter in this case, 4096 was picked semi-arbitrarily as a "nice-looking" number that is definitely bigger than the maximum message size.

#7 lore raw

PATCH v4 3/4 arm64: dts: apple: Add touchbar digitizer nodes

In reply to Sasha Finkelstein

From: Sasha Finkelstein <[email protected]>

Adds device tree entries for the touchbar digitizer

---
 arch/arm64/boot/dts/apple/t8103-j293.dts | 27 +++++++++++++++++++++++++++
 arch/arm64/boot/dts/apple/t8103.dtsi     | 19 +++++++++++++++++++
 arch/arm64/boot/dts/apple/t8112-j493.dts | 23 +++++++++++++++++++++++
 arch/arm64/boot/dts/apple/t8112.dtsi     | 14 ++++++++++++++
 4 files changed, 83 insertions(+)
arch/arm64/boot/dts/apple/t8103-j293.dts +27 -0
index 56b0c67bfcda321b60c621de092643017693ff91..0a93d3891c23da8b8c77dce64001caacb69ee140 100644
@@ -17,6 +17,14 @@ / {
 	compatible = "apple,j293", "apple,t8103", "apple,arm-platform";
 	model = "Apple MacBook Pro (13-inch, M1, 2020)";
 
+	/*
+	 * All of those are used by the bootloader to pass calibration
+	 * blobs and other device-specific properties
+	 */
+	aliases {
+		touchbar0 = &touchbar0;
+	};
+
 	led-controller {
 		compatible = "pwm-leds";
 		led-0 {
@@ -49,3 +57,22 @@ &i2c4 {
 &fpwm1 {
 	status = "okay";
 };
+
+&spi0 {
+	cs-gpios = <&pinctrl_ap 109 GPIO_ACTIVE_LOW>;
+	status = "okay";
+
+	touchbar0: touchbar@0 {
+		compatible = "apple,j293-touchbar";
+		reg = <0>;
+		spi-max-frequency = <11500000>;
+		spi-cs-setup-delay-ns = <2000>;
+		spi-cs-hold-delay-ns = <2000>;
+		reset-gpios = <&pinctrl_ap 139 GPIO_ACTIVE_LOW>;
+		interrupts-extended = <&pinctrl_ap 194 IRQ_TYPE_EDGE_FALLING>;
+		firmware-name = "apple/dfrmtfw-j293.bin";
+		touchscreen-size-x = <23045>;
+		touchscreen-size-y = <640>;
+		touchscreen-inverted-y;
+	};
+};
arch/arm64/boot/dts/apple/t8103.dtsi +19 -0
index 9b0dad6b618444ac6b1c9735c50cccfc3965f947..dc72aae3844bf33579f623f0b01abc7de4033af4 100644
@@ -326,6 +326,13 @@ clkref: clock-ref {
 		clock-output-names = "clkref";
 	};
 
+	clk_200m: clock-200m {
+		compatible = "fixed-clock";
+		#clock-cells = <0>;
+		clock-frequency = <200000000>;
+		clock-output-names = "clk_200m";
+	};
+
 	/*
 	 * This is a fabulated representation of the input clock
 	 * to NCO since we don't know the true clock tree.
@@ -441,6 +448,18 @@ fpwm1: pwm@235044000 {
 			status = "disabled";
 		};
 
+		spi0: spi@235100000 {
+			compatible = "apple,t8103-spi", "apple,spi";
+			reg = <0x2 0x35100000 0x0 0x4000>;
+			interrupt-parent = <&aic>;
+			interrupts = <AIC_IRQ 614 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&clk_200m>;
+			power-domains = <&ps_spi0>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			status = "disabled"; /* only used in J293 */
+		};
+
 		serial0: serial@235200000 {
 			compatible = "apple,s5l-uart";
 			reg = <0x2 0x35200000 0x0 0x1000>;
arch/arm64/boot/dts/apple/t8112-j493.dts +23 -0
index 0ad908349f55406783942735a2e9dad54cda00ec..045bd0716cb7d20c1379ebc1e3ff7f4d0dddc179 100644
@@ -17,8 +17,13 @@ / {
 	compatible = "apple,j493", "apple,t8112", "apple,arm-platform";
 	model = "Apple MacBook Pro (13-inch, M2, 2022)";
 
+	/*
+	 * All of those are used by the bootloader to pass calibration
+	 * blobs and other device-specific properties
+	 */
 	aliases {
 		bluetooth0 = &bluetooth0;
+		touchbar0 = &touchbar0;
 		wifi0 = &wifi0;
 	};
 
@@ -67,3 +72,21 @@ &i2c4 {
 &fpwm1 {
 	status = "okay";
 };
+
+&spi3 {
+	status = "okay";
+
+	touchbar0: touchbar@0 {
+		compatible = "apple,j493-touchbar";
+		reg = <0>;
+		spi-max-frequency = <8000000>;
+		spi-cs-setup-delay-ns = <2000>;
+		spi-cs-hold-delay-ns = <2000>;
+		reset-gpios = <&pinctrl_ap 170 GPIO_ACTIVE_LOW>;
+		interrupts-extended = <&pinctrl_ap 174 IRQ_TYPE_EDGE_FALLING>;
+		firmware-name = "apple/dfrmtfw-j493.bin";
+		touchscreen-size-x = <23045>;
+		touchscreen-size-y = <640>;
+		touchscreen-inverted-y;
+	};
+};
arch/arm64/boot/dts/apple/t8112.dtsi +14 -0
index 1666e6ab250bc0be9b8318e3c8fc903ccd3f3760..bb6c9e769c65330a32a3c7aa2f074c1f63e195fd 100644
@@ -467,6 +467,20 @@ fpwm1: pwm@235044000 {
 			status = "disabled";
 		};
 
+		spi3: spi@23510c000 {
+			compatible = "apple,t8112-spi", "apple,spi";
+			reg = <0x2 0x3510c000 0x0 0x4000>;
+			interrupt-parent = <&aic>;
+			interrupts = <AIC_IRQ 751 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&clkref>;
+			pinctrl-0 = <&spi3_pins>;
+			pinctrl-names = "default";
+			power-domains = <&ps_spi3>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			status = "disabled"; /* only used in J493 */
+		};
+
 		serial0: serial@235200000 {
 			compatible = "apple,s5l-uart";
 			reg = <0x2 0x35200000 0x0 0x1000>;
Signature · 1 line
2.48.0
Acked-by on v4 3/4
#8 lore raw

Re: [PATCH v4 3/4] arm64: dts: apple: Add touchbar digitizer nodes

Hi,

Quoted 9 lines · On Wed, Jan 15, 2025, at 23:46, Sasha Finkelstein via B4 Relay wrote:

From: Sasha Finkelstein <[email protected]>

Adds device tree entries for the touchbar digitizer

---

Thanks,

Sven

#9 lore raw

PATCH v4 4/4 MAINTAINERS: Add entries for Apple Z2 touchscreen driver

In reply to Sasha Finkelstein

Add the MAINTAINERS entries for the driver

---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)
MAINTAINERS +2 -0
index a87ddad78e26f28ffd0f3433560d6db1518f9f95..8b3776eb748e128f87c44886b117e0652447fb37 100644
@@ -2191,6 +2191,7 @@ F:	Documentation/devicetree/bindings/clock/apple,nco.yaml
 F:	Documentation/devicetree/bindings/cpufreq/apple,cluster-cpufreq.yaml
 F:	Documentation/devicetree/bindings/dma/apple,admac.yaml
 F:	Documentation/devicetree/bindings/i2c/apple,i2c.yaml
+F:	Documentation/devicetree/bindings/input/touchscreen/apple,z2-multitouch.yaml
 F:	Documentation/devicetree/bindings/interrupt-controller/apple,*
 F:	Documentation/devicetree/bindings/iommu/apple,dart.yaml
 F:	Documentation/devicetree/bindings/iommu/apple,sart.yaml
@@ -2211,6 +2212,7 @@ F:	drivers/dma/apple-admac.c
 F:	drivers/pmdomain/apple/
 F:	drivers/i2c/busses/i2c-pasemi-core.c
 F:	drivers/i2c/busses/i2c-pasemi-platform.c
+F:	drivers/input/touchscreen/apple_z2.c
 F:	drivers/iommu/apple-dart.c
 F:	drivers/iommu/io-pgtable-dart.c
 F:	drivers/irqchip/irq-apple-aic.c
Signature · 1 line
2.48.0
Acked-by on v4 4/4
#10 lore raw

Re: [PATCH v4 4/4] MAINTAINERS: Add entries for Apple Z2 touchscreen driver

Quoted 7 lines · On Wed, Jan 15, 2025, at 23:46, Sasha Finkelstein via B4 Relay wrote:

From: Sasha Finkelstein <[email protected]>

Add the MAINTAINERS entries for the driver

---

Quoted 29 lines
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)
MAINTAINERS +0 -0
index 

a87ddad78e26f28ffd0f3433560d6db1518f9f95..8b3776eb748e128f87c44886b117e0652447fb37 100644

MAINTAINERS +0 -0
@@ -2191,6 +2191,7 @@ 

F: Documentation/devicetree/bindings/clock/apple,nco.yaml
F: Documentation/devicetree/bindings/cpufreq/apple,cluster-cpufreq.yaml
F: Documentation/devicetree/bindings/dma/apple,admac.yaml
F: Documentation/devicetree/bindings/i2c/apple,i2c.yaml

MAINTAINERS +2 -0
+F:	Documentation/devicetree/bindings/input/touchscreen/apple,z2-multitouch.yaml
 F:	Documentation/devicetree/bindings/interrupt-controller/apple,*
 F:	Documentation/devicetree/bindings/iommu/apple,dart.yaml
 F:	Documentation/devicetree/bindings/iommu/apple,sart.yaml
@@ -2211,6 +2212,7 @@ F:	drivers/dma/apple-admac.c
 F:	drivers/pmdomain/apple/
 F:	drivers/i2c/busses/i2c-pasemi-core.c
 F:	drivers/i2c/busses/i2c-pasemi-platform.c
+F:	drivers/input/touchscreen/apple_z2.c
 F:	drivers/iommu/apple-dart.c
 F:	drivers/iommu/io-pgtable-dart.c
 F:	drivers/irqchip/irq-apple-aic.c
Signature · 2 lines
-- 
2.48.0