Delete 1002-Add-apple-ibridge-driver.patch

This commit is contained in:
Aditya Garg
2022-11-08 20:42:11 +05:30
committed by Aditya Garg
parent 9dcb1e2d25
commit 5054908dfe
11 changed files with 3034 additions and 3655 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,70 @@
From dc27d4db5787546ae5eacf3483f3b87f2d4fb1c1 Mon Sep 17 00:00:00 2001
From: Redecorating <69827514+Redecorating@users.noreply.github.com>
Date: Mon, 7 Nov 2022 14:56:34 +0530
Subject: [PATCH] Put apple-bce in drivers/staging
---
drivers/staging/Kconfig | 2 ++
drivers/staging/Makefile | 1 +
drivers/staging/apple-bce/Kconfig | 18 ++++++++++++++++++
drivers/staging/apple-bce/Makefile | 2 +-
4 files changed, 22 insertions(+), 1 deletion(-)
create mode 100644 drivers/staging/apple-bce/Kconfig
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index 5cfabd537..3b8e61d26 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -80,4 +80,6 @@ source "drivers/staging/qlge/Kconfig"
source "drivers/staging/vme_user/Kconfig"
+source "drivers/staging/apple-bce/Kconfig"
+
endif # STAGING
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index f8c3aa9c2..1e148d6c3 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -29,3 +29,4 @@ obj-$(CONFIG_PI433) += pi433/
obj-$(CONFIG_XIL_AXIS_FIFO) += axis-fifo/
obj-$(CONFIG_FIELDBUS_DEV) += fieldbus/
obj-$(CONFIG_QLGE) += qlge/
+obj-$(CONFIG_APPLE_BCE) += apple-bce/
diff --git a/drivers/staging/apple-bce/Kconfig b/drivers/staging/apple-bce/Kconfig
new file mode 100644
index 000000000..fe92bc441
--- /dev/null
+++ b/drivers/staging/apple-bce/Kconfig
@@ -0,0 +1,18 @@
+config APPLE_BCE
+ tristate "Apple BCE driver (VHCI and Audio support)"
+ default m
+ depends on X86
+ select SOUND
+ select SND
+ select SND_PCM
+ select SND_JACK
+ help
+ VHCI and audio support on Apple MacBooks with the T2 Chip.
+ This driver is divided in three components:
+ - BCE (Buffer Copy Engine): which establishes a basic communication
+ channel with the T2 chip. This component is required by the other two:
+ - VHCI (Virtual Host Controller Interface): Access to keyboard, mouse
+ and other system devices depend on this virtual USB host controller
+ - Audio: a driver for the T2 audio interface.
+
+ If "M" is selected, the module will be called apple-bce.'
diff --git a/drivers/staging/apple-bce/Makefile b/drivers/staging/apple-bce/Makefile
index a6a656f06..8cfbd3f64 100644
--- a/drivers/staging/apple-bce/Makefile
+++ b/drivers/staging/apple-bce/Makefile
@@ -1,5 +1,5 @@
modname := apple-bce
-obj-m += $(modname).o
+obj-$(CONFIG_APPLE_BCE) += $(modname).o
apple-bce-objs := apple_bce.o mailbox.o queue.o queue_dma.o vhci/vhci.o vhci/queue.o vhci/transfer.o audio/audio.o audio/protocol.o audio/protocol_bce.o audio/pcm.o
--
2.34.1
@@ -1,111 +0,0 @@
From 153b587ed53135eaf244144f6f8bdd5a0fe6b69e Mon Sep 17 00:00:00 2001
From: Redecorating <69827514+Redecorating@users.noreply.github.com>
Date: Fri, 24 Dec 2021 18:12:25 +1100
Subject: [PATCH 1/1] Put apple-bce and apple-ibridge in drivers/staging
---
drivers/staging/Kconfig | 4 ++++
drivers/staging/Makefile | 2 ++
drivers/staging/apple-bce/Kconfig | 18 ++++++++++++++++++
drivers/staging/apple-bce/Makefile | 2 +-
drivers/staging/apple-ibridge/Kconfig | 15 +++++++++++++++
drivers/staging/apple-ibridge/Makefile | 6 +++---
6 files changed, 43 insertions(+), 4 deletions(-)
create mode 100644 drivers/staging/apple-bce/Kconfig
create mode 100644 drivers/staging/apple-ibridge/Kconfig
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index e03627a..fc121d5 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -102,4 +102,8 @@ source "drivers/staging/qlge/Kconfig"
source "drivers/staging/vme_user/Kconfig"
+source "drivers/staging/apple-bce/Kconfig"
+
+source "drivers/staging/apple-ibridge/Kconfig"
+
endif # STAGING
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index c7f8d8d..debad40 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -41,3 +41,5 @@ obj-$(CONFIG_XIL_AXIS_FIFO) += axis-fifo/
obj-$(CONFIG_XIL_AXIS_FIFO) += axis-fifo/
obj-$(CONFIG_FIELDBUS_DEV) += fieldbus/
obj-$(CONFIG_QLGE) += qlge/
+obj-$(CONFIG_APPLE_BCE) += apple-bce/
+obj-$(CONFIG_APPLE_IBRIDGE) += apple-ibridge/
diff --git a/drivers/staging/apple-bce/Kconfig b/drivers/staging/apple-bce/Kconfig
new file mode 100644
index 0000000..bbfb89b
--- /dev/null
+++ b/drivers/staging/apple-bce/Kconfig
@@ -0,0 +1,18 @@
+config APPLE_BCE
+ tristate "Apple BCE driver (VHCI and Audio support)"
+ default m
+ depends on X86
+ select SOUND
+ select SND
+ select SND_PCM
+ select SND_JACK
+ help
+ VHCI and audio support on Apple MacBooks with the T2 Chip.
+ This driver is divided in three components:
+ - BCE (Buffer Copy Engine): which establishes a basic communication
+ channel with the T2 chip. This component is required by the other two:
+ - VHCI (Virtual Host Controller Interface): Access to keyboard, mouse
+ and other system devices depend on this virtual USB host controller
+ - Audio: a driver for the T2 audio interface.
+
+ If "M" is selected, the module will be called apple-bce.'
diff --git a/drivers/staging/apple-bce/Makefile b/drivers/staging/apple-bce/Makefile
index a6a656f..8cfbd3f 100644
--- a/drivers/staging/apple-bce/Makefile
+++ b/drivers/staging/apple-bce/Makefile
@@ -1,5 +1,5 @@
modname := apple-bce
-obj-m += $(modname).o
+obj-$(CONFIG_APPLE_BCE) += $(modname).o
apple-bce-objs := apple_bce.o mailbox.o queue.o queue_dma.o vhci/vhci.o vhci/queue.o vhci/transfer.o audio/audio.o audio/protocol.o audio/protocol_bce.o audio/pcm.o
diff --git a/drivers/staging/apple-ibridge/Kconfig b/drivers/staging/apple-ibridge/Kconfig
new file mode 100644
index 0000000..0716486
--- /dev/null
+++ b/drivers/staging/apple-ibridge/Kconfig
@@ -0,0 +1,15 @@
+config APPLE_IBRIDGE
+ tristate "Apple iBridge driver (Touchbar and ALS support)"
+ default m
+ depends on X86
+ select HID
+ select IIO
+ select IIO_TRIGGERED_BUFFER
+ select IIO_BUFFER
+ select ACPI_ALS
+ help
+ Driver for the Touchbar and ALS (Ambient Light Sensor) on some
+ Apple computers.
+
+ If "M" is selected, the modules will be called apple-ibridge,
+ apple-ib-tb and apple-ib-als.
diff --git a/drivers/staging/apple-ibridge/Makefile b/drivers/staging/apple-ibridge/Makefile
index ea40afe..ae129bd 100644
--- a/drivers/staging/apple-ibridge/Makefile
+++ b/drivers/staging/apple-ibridge/Makefile
@@ -1,6 +1,6 @@
-obj-m += apple-ibridge.o
-obj-m += apple-ib-tb.o
-obj-m += apple-ib-als.o
+obj-$(CONFIG_APPLE_IBRIDGE) += apple-ibridge.o
+obj-$(CONFIG_APPLE_IBRIDGE) += apple-ib-tb.o
+obj-$(CONFIG_APPLE_IBRIDGE) += apple-ib-als.o
KVERSION := $(KERNELRELEASE)
ifeq ($(origin KERNELRELEASE), undefined)
--
2.34.1
@@ -0,0 +1,63 @@
From 18bed33b3b1180a8af8a52dcf544b67b61786e89 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ronald=20Tschal=C3=A4r?= <ronald@innovation.ch>
Date: Sat, 27 Feb 2021 17:26:39 -0800
Subject: [PATCH 1/6] HID: Recognize sensors with application collections too.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
According to HUTRR39 logical sensor devices may be nested inside
physical collections or may be specified in multiple top-level
application collections (see page 59, strategies 1 and 2). However,
the current code was only recognizing those with physical collections.
This issue turned up in recent MacBook Pro's which define the ALS in
a top-level application collection.
Signed-off-by: Ronald Tschalär <ronald@innovation.ch>
---
drivers/hid/hid-core.c | 3 ++-
drivers/hid/hid-sensor-hub.c | 6 ++++--
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index b7f5566e338d..8fcd663b10e2 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -804,7 +804,8 @@ static void hid_scan_collection(struct hid_parser *parser, unsigned type)
int i;
if (((parser->global.usage_page << 16) == HID_UP_SENSOR) &&
- type == HID_COLLECTION_PHYSICAL)
+ (type == HID_COLLECTION_PHYSICAL ||
+ type == HID_COLLECTION_APPLICATION))
hid->group = HID_GROUP_SENSOR_HUB;
if (hid->vendor == USB_VENDOR_ID_MICROSOFT &&
diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
index 6abd3e2a9094..d03dc4ca095f 100644
--- a/drivers/hid/hid-sensor-hub.c
+++ b/drivers/hid/hid-sensor-hub.c
@@ -397,7 +397,8 @@ int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
for (i = 0; i < report->maxfield; ++i) {
field = report->field[i];
if (field->maxusage) {
- if (field->physical == usage_id &&
+ if ((field->physical == usage_id ||
+ field->application == usage_id) &&
(field->logical == attr_usage_id ||
field->usage[0].hid ==
attr_usage_id) &&
@@ -506,7 +507,8 @@ static int sensor_hub_raw_event(struct hid_device *hdev,
collection->usage);
callback = sensor_hub_get_callback(hdev,
- report->field[i]->physical,
+ report->field[i]->physical ?:
+ report->field[i]->application,
report->field[i]->usage[0].collection_index,
&hsdev, &priv);
if (!callback) {
--
2.38.1
@@ -0,0 +1,221 @@
From 360637979541fa2f3a64ed54af818f07e4e95a8d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ronald=20Tschal=C3=A4r?= <ronald@innovation.ch>
Date: Sat, 27 Feb 2021 17:26:41 -0800
Subject: [PATCH 2/6] HID: core: Export some report item parsing functions.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
These are useful to drivers that need to scan or parse reports
themselves.
Signed-off-by: Ronald Tschalär <ronald@innovation.ch>
---
drivers/hid/hid-core.c | 54 +++++++++++++++++++++++++-----------------
include/linux/hid.h | 4 ++++
2 files changed, 36 insertions(+), 22 deletions(-)
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 8fcd663b10e2..f0d914238e55 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -343,7 +343,7 @@ static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsign
* Read data value from item.
*/
-static u32 item_udata(struct hid_item *item)
+u32 hid_item_udata(struct hid_item *item)
{
switch (item->size) {
case 1: return item->data.u8;
@@ -352,8 +352,9 @@ static u32 item_udata(struct hid_item *item)
}
return 0;
}
+EXPORT_SYMBOL_GPL(hid_item_udata);
-static s32 item_sdata(struct hid_item *item)
+s32 hid_item_sdata(struct hid_item *item)
{
switch (item->size) {
case 1: return item->data.s8;
@@ -362,6 +363,7 @@ static s32 item_sdata(struct hid_item *item)
}
return 0;
}
+EXPORT_SYMBOL_GPL(hid_item_sdata);
/*
* Process a global item.
@@ -394,29 +396,29 @@ static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
return 0;
case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
- parser->global.usage_page = item_udata(item);
+ parser->global.usage_page = hid_item_udata(item);
return 0;
case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM:
- parser->global.logical_minimum = item_sdata(item);
+ parser->global.logical_minimum = hid_item_sdata(item);
return 0;
case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM:
if (parser->global.logical_minimum < 0)
- parser->global.logical_maximum = item_sdata(item);
+ parser->global.logical_maximum = hid_item_sdata(item);
else
- parser->global.logical_maximum = item_udata(item);
+ parser->global.logical_maximum = hid_item_udata(item);
return 0;
case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM:
- parser->global.physical_minimum = item_sdata(item);
+ parser->global.physical_minimum = hid_item_sdata(item);
return 0;
case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM:
if (parser->global.physical_minimum < 0)
- parser->global.physical_maximum = item_sdata(item);
+ parser->global.physical_maximum = hid_item_sdata(item);
else
- parser->global.physical_maximum = item_udata(item);
+ parser->global.physical_maximum = hid_item_udata(item);
return 0;
case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
@@ -424,7 +426,7 @@ static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
* nibble due to the common misunderstanding of HID
* specification 1.11, 6.2.2.7 Global Items. Attempt to handle
* both this and the standard encoding. */
- raw_value = item_sdata(item);
+ raw_value = hid_item_sdata(item);
if (!(raw_value & 0xfffffff0))
parser->global.unit_exponent = hid_snto32(raw_value, 4);
else
@@ -432,11 +434,11 @@ static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
return 0;
case HID_GLOBAL_ITEM_TAG_UNIT:
- parser->global.unit = item_udata(item);
+ parser->global.unit = hid_item_udata(item);
return 0;
case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
- parser->global.report_size = item_udata(item);
+ parser->global.report_size = hid_item_udata(item);
if (parser->global.report_size > 256) {
hid_err(parser->device, "invalid report_size %d\n",
parser->global.report_size);
@@ -445,7 +447,7 @@ static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
return 0;
case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
- parser->global.report_count = item_udata(item);
+ parser->global.report_count = hid_item_udata(item);
if (parser->global.report_count > HID_MAX_USAGES) {
hid_err(parser->device, "invalid report_count %d\n",
parser->global.report_count);
@@ -454,7 +456,7 @@ static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
return 0;
case HID_GLOBAL_ITEM_TAG_REPORT_ID:
- parser->global.report_id = item_udata(item);
+ parser->global.report_id = hid_item_udata(item);
if (parser->global.report_id == 0 ||
parser->global.report_id >= HID_MAX_IDS) {
hid_err(parser->device, "report_id %u is invalid\n",
@@ -479,7 +481,7 @@ static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
unsigned n;
__u32 count;
- data = item_udata(item);
+ data = hid_item_udata(item);
switch (item->tag) {
case HID_LOCAL_ITEM_TAG_DELIMITER:
@@ -611,7 +613,7 @@ static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
hid_concatenate_last_usage_page(parser);
- data = item_udata(item);
+ data = hid_item_udata(item);
switch (item->tag) {
case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
@@ -712,12 +714,19 @@ static void hid_device_release(struct device *dev)
kfree(hid);
}
-/*
+/**
+ * hid_fetch_item - fetch an item from a report
+ *
+ * @start: the current position in the report buffer to read the next item from
+ * @end: the end of the report buffer
+ * @item: the item struct to fill in
+ *
* Fetch a report description item from the data stream. We support long
* items, though they are not used yet.
+ *
+ * Return: the position of the next item in the report
*/
-
-static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
+u8 *hid_fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
{
u8 b;
@@ -778,6 +787,7 @@ static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
return NULL;
}
+EXPORT_SYMBOL_GPL(hid_fetch_item);
static void hid_scan_input_usage(struct hid_parser *parser, u32 usage)
{
@@ -836,7 +846,7 @@ static int hid_scan_main(struct hid_parser *parser, struct hid_item *item)
hid_concatenate_last_usage_page(parser);
- data = item_udata(item);
+ data = hid_item_udata(item);
switch (item->tag) {
case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
@@ -896,7 +906,7 @@ static int hid_scan_report(struct hid_device *hid)
* be robust against hid errors. Those errors will be raised by
* hid_open_report() anyway.
*/
- while ((start = fetch_item(start, end, &item)) != NULL)
+ while ((start = hid_fetch_item(start, end, &item)) != NULL)
dispatch_type[item.type](parser, &item);
/*
@@ -1255,7 +1265,7 @@ int hid_open_report(struct hid_device *device)
device->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
ret = -EINVAL;
- while ((next = fetch_item(start, end, &item)) != NULL) {
+ while ((next = hid_fetch_item(start, end, &item)) != NULL) {
start = next;
if (item.format != HID_ITEM_FORMAT_SHORT) {
diff --git a/include/linux/hid.h b/include/linux/hid.h
index 4363a63b9775..b39f97d565e2 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -941,6 +941,10 @@ struct hid_report *hid_validate_values(struct hid_device *hid,
unsigned int field_index,
unsigned int report_counts);
+u32 hid_item_udata(struct hid_item *item);
+s32 hid_item_sdata(struct hid_item *item);
+u8 *hid_fetch_item(__u8 *start, __u8 *end, struct hid_item *item);
+
void hid_setup_resolution_multiplier(struct hid_device *hid);
int hid_open_report(struct hid_device *device);
int hid_check_keys_pressed(struct hid_device *hid);
--
2.38.1
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,233 @@
From c36014bd8cbf435a3668dbe257cb3d4293968074 Mon Sep 17 00:00:00 2001
From: Orlando Chamberlain <redecorating@protonmail.com>
Date: Sun, 6 Nov 2022 19:23:56 +0300
Subject: [PATCH 5/6] HID: apple-touchbar: support magic keyboard backlight
MacBookPro16,1/2/3/4 have the magic keyboard, with the keyboard
backlight controlled via the Touch Bar Backlight USB device.
We check that the internal keyboard's USB product ID matches that of
models with the magic keyboard, and then we create a sysfs led class
dev that controls the backlight.
NOTE: This commit hasn't been signed off yet
---
drivers/hid/apple-touchbar.c | 167 +++++++++++++++++++++++++++++++++++
1 file changed, 167 insertions(+)
diff --git a/drivers/hid/apple-touchbar.c b/drivers/hid/apple-touchbar.c
index 87cb9ebafb61..e2cf41b35363 100644
--- a/drivers/hid/apple-touchbar.c
+++ b/drivers/hid/apple-touchbar.c
@@ -78,6 +78,8 @@
#define APPLETB_FEATURE_IS_T1 BIT(0)
+#define APPLE_MAGIC_KBD_BL_MAX 60
+
static int appletb_tb_def_idle_timeout = 5 * 60;
module_param_named(idle_timeout, appletb_tb_def_idle_timeout, int, 0444);
MODULE_PARM_DESC(idle_timeout, "Default touch bar idle timeout:\n"
@@ -136,6 +138,12 @@ static const struct attribute_group appletb_attr_group = {
.attrs = appletb_attrs,
};
+struct apple_magic_backlight {
+ struct led_classdev cdev;
+ struct usb_device *dev;
+ bool powered;
+};
+
struct appletb_device {
bool active;
struct device *log_dev;
@@ -175,6 +183,8 @@ struct appletb_device {
int fn_mode;
bool is_t1;
+
+ struct apple_magic_backlight kbd_backlight;
};
struct appletb_key_translation {
@@ -197,6 +207,30 @@ static const struct appletb_key_translation appletb_fn_codes[] = {
{ KEY_F12, KEY_VOLUMEUP },
};
+struct apple_magic_keyboard_backlight_brightness_report {
+ u8 report_id; /* 0x01 */
+ u8 mode; /* If 0x00, brightness can turn off backlight */
+ u8 brightness;
+ u8 override_1; /* If these are non-zero, backlight is overridden to max brightness */
+ u8 override_2;
+ u8 max; /* Lower is brighter, only takes effect when turning backlight
+ * on from off, can be unreliable
+ */
+ u8 rate;
+ u8 magic_1; /* If these are non-zero, we are ignored. */
+ u8 magic_2;
+};
+
+struct apple_magic_keyboard_backlight_power_report {
+ u8 report_id; /* 0x03 */
+ u8 power;
+ u8 max; /* Lower is brighter, only takes effect when turning backlight
+ * on from off, can be unreliable
+ */
+ u8 rate;
+ u8 magic_1; /* If these are non-zero, we are ignored. */
+ u8 magic_2;
+};
static struct appletb_device *appletb_dev;
static int appletb_send_usb_ctrl(struct appletb_iface_info *iface_info,
@@ -317,6 +351,132 @@ static int appletb_send_hid_report(struct appletb_iface_info *iface_info,
return rc;
}
+static int apple_magic_keyboard_backlight_power_set(struct apple_magic_backlight *backlight,
+ char power, char rate)
+{
+ int tries = 0;
+ int rc;
+ struct apple_magic_keyboard_backlight_power_report *rep;
+
+ rep = kmalloc(sizeof(*rep), GFP_KERNEL);
+ if (rep == NULL)
+ return -ENOMEM;
+
+ backlight->powered = power ? true : false;
+
+ rep->report_id = 0x03;
+ rep->power = power;
+ rep->max = 0x5e; /* Windows uses 0x5e when turning on, and 0xf4 when
+ * turning off. When it's off it doesn't matter, so
+ * use 0x5e
+ */
+ rep->rate = rate;
+
+ do {
+ /*
+ * FIXME: use appletb_send_hid_report, don't hard code all of this
+ * Need to get apple_tb_send_hid_report to use wIndex=0x01
+ */
+ rc = usb_control_msg(backlight->dev,
+ usb_sndctrlpipe(backlight->dev, 0),
+ HID_REQ_SET_REPORT, USB_DIR_OUT |
+ USB_TYPE_CLASS | USB_RECIP_INTERFACE,
+ 0x0303, 0x01, rep, sizeof(*rep),
+ 2000);
+ if (rc != -EPIPE)
+ break;
+
+ usleep_range(1000 << tries, 3000 << tries);
+ } while (++tries < 5);
+
+ kfree(rep);
+ return (rc > 0) ? 0 : rc;
+}
+
+static int apple_magic_keyboard_backlight_brightness_set(struct apple_magic_backlight *backlight,
+ char brightness, char rate)
+{
+ int tries = 0;
+ int rc;
+ struct apple_magic_keyboard_backlight_brightness_report *rep;
+
+ rep = kmalloc(sizeof(*rep), GFP_KERNEL);
+ if (rep == NULL)
+ return -ENOMEM;
+
+ rep->report_id = 0x01;
+ rep->mode = brightness;
+ rep->brightness = brightness;
+ rep->max = 0x5e;
+ rep->rate = rate;
+
+ do {
+ /*
+ * FIXME: use appletb_send_hid_report, don't hard code all of this
+ * Need to get apple_tb_send_hid_report to use wIndex=0x01
+ */
+ rc = usb_control_msg(backlight->dev,
+ usb_sndctrlpipe(backlight->dev, 0),
+ HID_REQ_SET_REPORT, USB_DIR_OUT |
+ USB_TYPE_CLASS | USB_RECIP_INTERFACE,
+ 0x0301, 0x01, rep, sizeof(*rep),
+ 2000);
+ if (rc != -EPIPE)
+ break;
+
+ usleep_range(1000 << tries, 3000 << tries);
+ } while (++tries < 5);
+
+ kfree(rep);
+ return (rc > 0) ? 0 : rc;
+}
+
+static int apple_magic_keyboard_backlight_set(struct apple_magic_backlight *backlight,
+ char brightness, char rate)
+{
+ int rc;
+
+ if (!brightness)
+ return apple_magic_keyboard_backlight_power_set(backlight, 0, rate);
+
+ rc = apple_magic_keyboard_backlight_brightness_set(backlight, brightness, rate);
+ if (rc)
+ return rc;
+
+ if (!backlight->powered && brightness)
+ rc = apple_magic_keyboard_backlight_power_set(backlight, 1, rate);
+
+ return (rc > 0) ? 0 : rc;
+}
+
+static int apple_magic_keyboard_backlight_led_set(struct led_classdev *led_cdev,
+ enum led_brightness brightness)
+{
+ struct apple_magic_backlight *backlight = container_of(led_cdev,
+ struct apple_magic_backlight, cdev);
+
+ return apple_magic_keyboard_backlight_set(backlight, brightness, 1);
+}
+
+static int apple_magic_keyboard_backlight_init(struct appletb_device *tb_dev)
+{
+ int ret;
+
+ tb_dev->kbd_backlight.dev = interface_to_usbdev(tb_dev->disp_iface.usb_iface);
+ tb_dev->kbd_backlight.cdev.name = "apple::kbd_backlight";
+ tb_dev->kbd_backlight.cdev.max_brightness = APPLE_MAGIC_KBD_BL_MAX;
+ tb_dev->kbd_backlight.cdev.brightness_set_blocking = apple_magic_keyboard_backlight_led_set;
+
+ ret = apple_magic_keyboard_backlight_set(&tb_dev->kbd_backlight, 0, 0);
+ if (ret) {
+ dev_err(tb_dev->log_dev,
+ "Failed to initialise Magic Keyboard Backlight (%d)\n", ret);
+ return ret;
+ }
+
+ return devm_led_classdev_register(tb_dev->log_dev, &tb_dev->kbd_backlight.cdev);
+}
+
static int appletb_set_tb_disp(struct appletb_device *tb_dev,
unsigned char disp)
{
@@ -881,6 +1041,13 @@ static int appletb_inp_connect(struct input_handler *handler,
if (id->driver_info == APPLETB_DEVID_KEYBOARD) {
handle = &tb_dev->kbd_handle;
handle->name = "tbkbd";
+ switch (dev->id.product) {
+ case 0x0340u: /* MacBookPro16,1/4 */
+ case 0x027eu: /* MacBookPro16,2 */
+ case 0x027fu: /* MacBookPro16,3 */
+ apple_magic_keyboard_backlight_init(tb_dev);
+ break;
+ }
} else if (id->driver_info == APPLETB_DEVID_TOUCHPAD) {
handle = &tb_dev->tpd_handle;
handle->name = "tbtpad";
--
2.38.1
@@ -0,0 +1,35 @@
From 17d3c266246722505ef5bddd470d532d2dd75a3f Mon Sep 17 00:00:00 2001
From: Aditya Garg <gargaditya08@live.com>
Date: Mon, 7 Nov 2022 01:17:17 +0530
Subject: [PATCH 6/6] HID: quirks: Use touchbar quirks when touchbar driver is
enabled
Signed-off-by: Aditya Garg <gargaditya08@live.com>
---
drivers/hid/hid-quirks.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c
index cc862fbf1995..32ff8b7b336f 100644
--- a/drivers/hid/hid-quirks.c
+++ b/drivers/hid/hid-quirks.c
@@ -314,12 +314,14 @@ static const struct hid_device_id hid_have_special_driver[] = {
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021) },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021) },
- { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_TOUCHBAR_BACKLIGHT) },
- { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_TOUCHBAR_DISPLAY) },
#endif
#if IS_ENABLED(CONFIG_HID_APPLE_IBRIDGE)
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IBRIDGE) },
#endif
+#if IS_ENABLED(CONFIG_HID_APPLE_TOUCHBAR)
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_TOUCHBAR_BACKLIGHT) },
+ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_TOUCHBAR_DISPLAY) },
+#endif
#if IS_ENABLED(CONFIG_HID_APPLEIR)
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL) },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL2) },
--
2.38.1
-144
View File
@@ -1,144 +0,0 @@
From 4f50f041554c78aaa821585ce583946ecdae91b3 Mon Sep 17 00:00:00 2001
From: Ard Biesheuvel <ardb@kernel.org>
Date: Thu, 27 Oct 2022 15:52:31 +0200
Subject: efi: efivars: Fix variable writes with unsupported
query_variable_store()
Commit 8a254d90a775 ("efi: efivars: Fix variable writes without
query_variable_store()") addressed an issue that was introduced during
the EFI variable store refactor, where alternative implementations of
the efivars layer that lacked query_variable_store() would no longer
work.
Unfortunately, there is another case to consider here, which was missed:
if the efivars layer is backed by the EFI runtime services as usual, but
the EFI implementation predates the introduction of QueryVariableInfo(),
we will return EFI_UNSUPPORTED, and this is no longer being dealt with
correctly.
So let's fix this, and while at it, clean up the code a bit, by merging
the check_var_size() routines as well as their callers.
Cc: <stable@vger.kernel.org> # v6.0
Fixes: bbc6d2c6ef22 ("efi: vars: Switch to new wrapper layer")
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/firmware/efi/vars.c | 68 +++++++++++++--------------------------------
1 file changed, 20 insertions(+), 48 deletions(-)
diff --git a/drivers/firmware/efi/vars.c b/drivers/firmware/efi/vars.c
index 433b615871395..0ba9f18312f5b 100644
--- a/drivers/firmware/efi/vars.c
+++ b/drivers/firmware/efi/vars.c
@@ -21,29 +21,22 @@ static struct efivars *__efivars;
static DEFINE_SEMAPHORE(efivars_lock);
-static efi_status_t check_var_size(u32 attributes, unsigned long size)
-{
- const struct efivar_operations *fops;
-
- fops = __efivars->ops;
-
- if (!fops->query_variable_store)
- return (size <= SZ_64K) ? EFI_SUCCESS : EFI_OUT_OF_RESOURCES;
-
- return fops->query_variable_store(attributes, size, false);
-}
-
-static
-efi_status_t check_var_size_nonblocking(u32 attributes, unsigned long size)
+static efi_status_t check_var_size(bool nonblocking, u32 attributes,
+ unsigned long size)
{
const struct efivar_operations *fops;
+ efi_status_t status;
fops = __efivars->ops;
if (!fops->query_variable_store)
+ status = EFI_UNSUPPORTED;
+ else
+ status = fops->query_variable_store(attributes, size,
+ nonblocking);
+ if (status == EFI_UNSUPPORTED)
return (size <= SZ_64K) ? EFI_SUCCESS : EFI_OUT_OF_RESOURCES;
-
- return fops->query_variable_store(attributes, size, true);
+ return status;
}
/**
@@ -195,26 +188,6 @@ efi_status_t efivar_get_next_variable(unsigned long *name_size,
}
EXPORT_SYMBOL_NS_GPL(efivar_get_next_variable, EFIVAR);
-/*
- * efivar_set_variable_blocking() - local helper function for set_variable
- *
- * Must be called with efivars_lock held.
- */
-static efi_status_t
-efivar_set_variable_blocking(efi_char16_t *name, efi_guid_t *vendor,
- u32 attr, unsigned long data_size, void *data)
-{
- efi_status_t status;
-
- if (data_size > 0) {
- status = check_var_size(attr, data_size +
- ucs2_strsize(name, 1024));
- if (status != EFI_SUCCESS)
- return status;
- }
- return __efivars->ops->set_variable(name, vendor, attr, data_size, data);
-}
-
/*
* efivar_set_variable_locked() - set a variable identified by name/vendor
*
@@ -228,23 +201,21 @@ efi_status_t efivar_set_variable_locked(efi_char16_t *name, efi_guid_t *vendor,
efi_set_variable_t *setvar;
efi_status_t status;
- if (!nonblocking)
- return efivar_set_variable_blocking(name, vendor, attr,
- data_size, data);
+ if (data_size > 0) {
+ status = check_var_size(nonblocking, attr,
+ data_size + ucs2_strsize(name, 1024));
+ if (status != EFI_SUCCESS)
+ return status;
+ }
/*
* If no _nonblocking variant exists, the ordinary one
* is assumed to be non-blocking.
*/
- setvar = __efivars->ops->set_variable_nonblocking ?:
- __efivars->ops->set_variable;
+ setvar = __efivars->ops->set_variable_nonblocking;
+ if (!setvar || !nonblocking)
+ setvar = __efivars->ops->set_variable;
- if (data_size > 0) {
- status = check_var_size_nonblocking(attr, data_size +
- ucs2_strsize(name, 1024));
- if (status != EFI_SUCCESS)
- return status;
- }
return setvar(name, vendor, attr, data_size, data);
}
EXPORT_SYMBOL_NS_GPL(efivar_set_variable_locked, EFIVAR);
@@ -264,7 +235,8 @@ efi_status_t efivar_set_variable(efi_char16_t *name, efi_guid_t *vendor,
if (efivar_lock())
return EFI_ABORTED;
- status = efivar_set_variable_blocking(name, vendor, attr, data_size, data);
+ status = efivar_set_variable_locked(name, vendor, attr, data_size,
+ data, false);
efivar_unlock();
return status;
}
--
cgit