Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,25 @@ properties:

firmware-name:
maxItems: 1
description:
Firmware file name. With apple,firmware-prefix, the file used when
the bootloader passes no personality.

apple,firmware-prefix:
$ref: /schemas/types.yaml#/definitions/string
description:
Start of the firmware file names on a board whose controllers come
with more than one firmware personality. The driver loads
<prefix>-<personality>.bin, the personality in lower case with its
comma as a dash (C1F5D,4 gives <prefix>-c1f5d-4.bin), and leaves the
touchscreen off if that file is missing.

apple,hid-merge-personality:
$ref: /schemas/types.yaml#/definitions/string
description:
Touch firmware personality from this unit's Apple Device Tree.
The bootloader supplies it together with the calibration, so it is
absent from the static DTB.

apple,z2-cal-blob:
$ref: /schemas/types.yaml#/definitions/uint8-array
Expand Down
1 change: 1 addition & 0 deletions arch/arm64/boot/dts/apple/t8015-8.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
hv-supply = <&touch_hv>;
clocks = <&touchclk>;
firmware-name = "apple/dfrmtfw-d20-c1f5d-3.bin";
apple,firmware-prefix = "apple/dfrmtfw-d20";
touchscreen-size-x = <750>;
touchscreen-size-y = <1334>;
};
Expand Down
9 changes: 6 additions & 3 deletions arch/arm64/boot/dts/apple/t8015-8plus.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
#include "t8015-8.dtsi"

/*
* The D21 and D211 ADTs carry the same touch node: personality C1F5E,3,
* the same pins, power and clock functions. Their IPSW has one multitouch
* file, D21.mtprops, whose C1F5E,4 entry is the controller firmware.
* The D21 and D211 ADTs carry the same touch node: the same pins, power
* and clock functions. Their IPSW has one multitouch file, D21.mtprops,
* with a C1F5E,3 and a C1F5E,4 firmware; the unit's ADT personality picks
* one (the IPSW's ADT says C1F5E,3, the boot ADT of each unit says which
* its controller needs). C1F5E,4 is the one tested.
*/
&touchscreen {
compatible = "apple,d21-touchscreen";
firmware-name = "apple/dfrmtfw-d21-c1f5e-4.bin";
apple,firmware-prefix = "apple/dfrmtfw-d21";
touchscreen-size-x = <1080>;
touchscreen-size-y = <1920>;
};
Expand Down
5 changes: 0 additions & 5 deletions arch/arm64/boot/dts/apple/t8015-d20.dts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
model = "Apple iPhone 8 (Global)";
};

/* The ADT personality is C1F5D,3; use the D20 mtprops-derived container. */
&touchscreen {
firmware-name = "apple/dfrmtfw-d20-c1f5d-3.bin";
};

/* The D20's Wi-Fi module, as its ADT's wlan module-instance names it */
&wifi0 {
brcm,board-type = "apple,apolloe";
Expand Down
3 changes: 2 additions & 1 deletion arch/arm64/boot/dts/apple/t8015-d201.dts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
};


/* Same C1F5D,3 personality; pinctrl/PMIC phandle numbers differ in the ADT. */
/* The bootloader supplies this unit's C1F5D personality and calibration. */
&touchscreen {
compatible = "apple,d201-touchscreen";
firmware-name = "apple/dfrmtfw-d201-c1f5d-3.bin";
apple,firmware-prefix = "apple/dfrmtfw-d201";
};

/* The D201's Wi-Fi module, as its ADT's wlan module-instance names it */
Expand Down
47 changes: 47 additions & 0 deletions drivers/input/touchscreen/apple_z2.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <linux/bitrev.h>
#include <linux/bits.h>
#include <linux/clk.h>
#include <linux/ctype.h>
#include <linux/delay.h>
#include <linux/firmware.h>
#include <linux/gpio/consumer.h>
Expand All @@ -23,11 +24,54 @@
#include <linux/mutex.h>
#include <linux/of.h>
#include <linux/pinctrl/consumer.h>
#include <linux/property.h>
#include <linux/regulator/consumer.h>
#include <linux/spi/spi.h>
#include <linux/unaligned.h>
#include <linux/workqueue.h>

/*
* Apple's touch firmware comes in variants ("personalities"), and each
* unit's ADT names the one its controller needs; m1n1 passes that on as
* apple,hid-merge-personality. Where a board's IPSW carries more than one,
* the device tree names the files' common start in apple,firmware-prefix,
* and a unit's file is <prefix>-<personality>.bin, the personality in lower
* case with its comma as a dash (C1F5D,4: <prefix>-c1f5d-4.bin). If that
* file is missing, the touchscreen stays off and the log names it: a unit
* never gets another personality's firmware.
*
* Without apple,firmware-prefix, or when the bootloader passes no
* personality, firmware-name is the file, as before.
*/
static const char *apple_z2_fw_name(struct device *dev, const char *fw_name)
{
const char *prefix, *personality, *c;
char *name, *p;

if (device_property_read_string(dev, "apple,firmware-prefix", &prefix))
return fw_name;
if (device_property_read_string(dev, "apple,hid-merge-personality",
&personality)) {
dev_info(dev, "no touch personality from the bootloader, loading %s\n",
fw_name);
return fw_name;
}
for (c = personality; *c; c++)
if (!isalnum(*c) && *c != ',' && *c != '-')
break;
if (*c || c == personality) {
dev_err(dev, "bad touch personality \"%s\"\n", personality);
return ERR_PTR(-EINVAL);
}
name = devm_kasprintf(dev, GFP_KERNEL, "%s-%s.bin", prefix, personality);
if (!name)
return ERR_PTR(-ENOMEM);
for (p = name + strlen(prefix) + 1; *p; p++)
*p = *p == ',' ? '-' : tolower(*p);
dev_info(dev, "touch personality %s: %s\n", personality, name);
return name;
}

#include "apple_z2_n61.h"
#include "apple_z2_j72.h"
#include "apple_z2_d21.h"
Expand Down Expand Up @@ -6207,6 +6251,9 @@ static int apple_z2_probe(struct spi_device *spi)
error = device_property_read_string(dev, "firmware-name", &z2->fw_name);
if (error)
return dev_err_probe(dev, error, "unable to get firmware name\n");
z2->fw_name = apple_z2_fw_name(dev, z2->fw_name);
if (IS_ERR(z2->fw_name))
return PTR_ERR(z2->fw_name);
if (apple_z2_is_iphone7_plus(z2)) {
static const struct {
const char *name;
Expand Down
25 changes: 17 additions & 8 deletions drivers/input/touchscreen/apple_z2_d21.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ static int apple_z2_d21_smc_rw(struct apple_smc *smc, smc_key key,
#define APPLE_Z2_D21_FW_CONFIG_CPHA BIT(3)
#define APPLE_Z2_D21_FW_CONFIG_CPOL BIT(4)
#define APPLE_Z2_D21_FW_CONFIG_BOOT_TIMEOUT BIT(8)
#define APPLE_Z2_D21_FW_CONFIG_HBPP_VERSION BIT(11)

enum apple_z2_d21_protocol_state {
APPLE_Z2_D21_STATE_OFF,
Expand Down Expand Up @@ -197,6 +198,7 @@ struct apple_z2_d21 {
unsigned int z2_inter_packet_delay_us;
unsigned int z2_cs_delay_us;
unsigned int boot_timeout_ms;
u32 hbpp_version;
s16 sensor_max_x;
s16 sensor_min_x;
s16 sensor_max_y;
Expand Down Expand Up @@ -2978,15 +2980,10 @@ static const u8 *apple_z2_d21_build_iphone7_cal(struct apple_z2_d21 *z2,

put_unaligned_be16(0x18e1, blob_data);
put_unaligned_be16(APPLE_Z2_D21_HBPP_CMD_BLOB, blob_data + 2);
/*
* The length field counts the payload words less one. Apple's own
* container for this part stores its firmware blobs that way (63592
* bytes carries 15897, 17312 carries 4327), and the calibration packet
* shares the framing. Sending the plain word count makes the packet one
* word too long, so the controller reads into the trailing checksum and
* rejects every calibration blob.
/* Legacy containers retain their minus-one framing. A container that
* explicitly declares HBPP 0x103 uses the full payload word count.
*/
put_unaligned_be16(words - 1, blob_data + 4);
put_unaligned_be16(words - (z2->hbpp_version >= 0x104), blob_data + 4);
put_unaligned_be16(address, blob_data + 6);
put_unaligned_be16(address >> 16, blob_data + 8);
header_checksum = 0;
Expand Down Expand Up @@ -3234,6 +3231,13 @@ static int apple_z2_d21_apply_fw_config(struct apple_z2_d21 *z2, const u8 *data,
cpha = apple_z2_d21_fw_config_word(data, 4);
cpol = apple_z2_d21_fw_config_word(data, 5);
boot_timeout = apple_z2_d21_fw_config_word(data, 9);
if (valid & APPLE_Z2_D21_FW_CONFIG_HBPP_VERSION) {
u32 version = apple_z2_d21_fw_config_word(data, 10);

if (version != 0x103 && version != 0x104)
return -EINVAL;
z2->hbpp_version = version;
}
if ((valid & APPLE_Z2_D21_FW_CONFIG_MIN_DMA) && min_dma) {
if (apple_z2_d21_uses_iphone_protocol(z2)) {
if (min_dma > APPLE_Z2_D21_RX_BUF_SIZE)
Expand Down Expand Up @@ -5355,6 +5359,8 @@ static int apple_z2_d21_probe(struct spi_device *spi,

z2->spidev = spi;
z2->variant = info->variant;
/* Preserve existing containers that do not declare HBPP framing. */
z2->hbpp_version = 0x104;
z2->boot_timeout_ms = 20;
if (apple_z2_d21_uses_iphone_protocol(z2)) {
z2->z2_inter_packet_delay_us = 1000;
Expand Down Expand Up @@ -5509,6 +5515,9 @@ static int apple_z2_d21_probe(struct spi_device *spi,
error = device_property_read_string(dev, "firmware-name", &z2->fw_name);
if (error)
return dev_err_probe(dev, error, "unable to get firmware name\n");
z2->fw_name = apple_z2_fw_name(dev, z2->fw_name);
if (IS_ERR(z2->fw_name))
return PTR_ERR(z2->fw_name);
if (apple_z2_d21_uses_iphone_protocol(z2)) {
static const struct {
const char *name;
Expand Down
Loading