Touch Bar and ALS support for MacBook Pro's
Subsystems (3)
cover Touch Bar and ALS support for MacBook Pro's
This patch set provides Touch Bar and ALS support on MacBook Pro's 13,*, 14,*, and 15,*.
Some time a go an earlier version of these were posted to the list; all code comments from there have been incorporated. In addition the approach has been cleaned up, especially given that we now know how the 15,* models are implemented, so that the ibridge driver is only needed for the pre-15,* models and the ALS and Touch Bar drivers work unchanged for all models.
Ronald Tschalär (5):
HID: Recognize sensors with application collections too.
iio: hid-sensor-als: Support change sensitivity in illuminance too.
HID: core: Export some report item parsing functions.
HID: apple-ibridge: Add Apple iBridge HID driver for T1 chip.
HID: apple-touchbar - Add driver for the Touch Bar on MacBook Pro's.
drivers/hid/Kconfig | 26 + drivers/hid/Makefile | 2 + drivers/hid/apple-ibridge.c | 682 +++++++++++++ drivers/hid/apple-ibridge.h | 15 + drivers/hid/apple-touchbar.c | 1523 ++++++++++++++++++++++++++++ drivers/hid/hid-core.c | 57 +- drivers/hid/hid-ids.h | 1 + drivers/hid/hid-quirks.c | 3 + drivers/hid/hid-sensor-hub.c | 6 +- drivers/iio/light/hid-sensor-als.c | 8 + include/linux/hid.h | 4 + 11 files changed, 2302 insertions(+), 25 deletions(-) create mode 100644 drivers/hid/apple-ibridge.c create mode 100644 drivers/hid/apple-ibridge.h create mode 100644 drivers/hid/apple-touchbar.c
Signature · 1 line
2.26.2
PATCH 1/5 HID: Recognize sensors with application collections too.
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.
--- drivers/hid/hid-core.c | 3 ++- drivers/hid/hid-sensor-hub.c | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/hid/hid-core.c +2 -1
@@ -799,7 +799,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 &&
drivers/hid/hid-sensor-hub.c +4 -2
@@ -393,7 +393,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) &&
@@ -502,7 +503,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) {
Signature · 1 line
2.26.2
PATCH 2/5 iio: hid-sensor-als: Support change sensitivity in illuminance too.
In reply to Ronald TschalärRecent MacBook Pro's specify the usage of the change sensitivity field as illuminance (with a change sensitivity modifier) rather than as light.
--- drivers/iio/light/hid-sensor-als.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/iio/light/hid-sensor-als.c +8 -0
@@ -252,6 +252,14 @@ static int als_parse_report(struct platform_device *pdev,HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |HID_USAGE_SENSOR_DATA_LIGHT , &st->common_attributes.sensitivity); + +if (st->common_attributes.sensitivity.index <0 ) +sensor_hub_input_get_attribute_info (hsdev, +HID_FEATURE_REPORT , usage_id, +HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS | +HID_USAGE_SENSOR_LIGHT_ILLUM , + &st->common_attributes.sensitivity); +dev_dbg (&pdev->dev,"Sensitivity index:report %d:%d\n" , st->common_attributes.sensitivity.index, st->common_attributes.sensitivity.report_id);
Signature · 1 line
2.26.2
Re: [PATCH 2/5] iio: hid-sensor-als: Support change sensitivity in illuminance too.
Quoted 5 lines · On Sat, 27 Feb 2021 17:26:40 -0800 Ronald Tschalär <[email protected]> wrote:
Recent MacBook Pro's specify the usage of the change sensitivity field as illuminance (with a change sensitivity modifier) rather than as light.
Signed-off-by Ronald Tschalär <[email protected]>
This looks fine to me though it the hid sensors spec never fails to surprise me in the different slight variants of the same thing that come up.
Illuminance is at least fairly well defined, but who knows what for the DATA_LIGHT version takes?
Anyhow, lets give time for Srinivas to sanity check this as he's much more familiar with that spec than I am.
Jonathan
Quoted 23 lines
--- drivers/iio/light/hid-sensor-als.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/iio/light/hid-sensor-als.c +8
-0@@ -252,6 +252,14 @@ static int als_parse_report(struct platform_device *pdev,HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |HID_USAGE_SENSOR_DATA_LIGHT , &st->common_attributes.sensitivity); + +if (st->common_attributes.sensitivity.index <0 ) +sensor_hub_input_get_attribute_info (hsdev, +HID_FEATURE_REPORT , usage_id, +HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS | +HID_USAGE_SENSOR_LIGHT_ILLUM , + &st->common_attributes.sensitivity); +dev_dbg (&pdev->dev,"Sensitivity index:report %d:%d\n" , st->common_attributes.sensitivity.index, st->common_attributes.sensitivity.report_id);
Srinivas Pandruvada
maintainerRe: [PATCH 2/5] iio: hid-sensor-als: Support change sensitivity in illuminance too.
Quoted 8 lines · Jonathan Cameron
Quoted 5 lines · On Sat, 27 Feb 2021 17:26:40 -0800 Ronald Tschalär <[email protected]> wrote:
Recent MacBook Pro's specify the usage of the change sensitivity field
as illuminance (with a change sensitivity modifier) rather than as light.
Quoted 8 lines
Quoted 1 line
Signed-off-by Ronald Tschalär <[email protected]>This looks fine to me though it the hid sensors spec never fails to surprise
me in the different slight variants of the same thing that come up.Illuminance is at least fairly well defined, but who knows what for the
DATA_LIGHT
version takes?
The current implementations are deploying using "HID_USAGE_SENSOR_LIGHT_ILLUM" usage id 0xD1 for input. So this is natural to use the same usage id for sensitivity. So patch looks good to me.
But most implementation choose to use DATA_LIGHT for the sensitivity. probably referring to change in quantity of light without referring to area. There are no obvious units specified for DATA_LIGHT in the spec.
Thanks,
Srinivas
Quoted 34 lines
Anyhow, lets give time for Srinivas to sanity check this as he's much more familiar
with that spec than I am.Jonathan
Quoted 27 lines
--- drivers/iio/light/hid-sensor-als.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/iio/light/hid-sensor-als.c +0
-0@@ -252,6 +252,14 @@ static int als_parse_report(structplatform_device *pdev,HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_AB S |
drivers/iio/light/hid-sensor-als.c +5
-0HID_USAGE_SENSOR_DATA_LIGHT , &st->common_attributes.sensitivity); + +if (st->common_attributes.sensitivity.index <0 ) +sensor_hub_input_get_attribute_info (hsdev, +HID_FEATURE_REPORT , usage_id, + HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSIT
IVITY_ABS|drivers/iio/light/hid-sensor-als.c +3
-0+HID_USAGE_SENSOR_LIGHT_ILLUM , + &st->common_attributes.sensitivity); +dev_dbg (&pdev->dev,"Sensitivity index:report %d:%d\n" , st->common_attributes.sensitivity.index, st->common_attributes.sensitivity.report_id);
PATCH 3/5 HID: core: Export some report item parsing functions.
In reply to Ronald TschalärThese are useful to drivers that need to scan or parse reports themselves.
--- drivers/hid/hid-core.c | 54 +++++++++++++++++++++++++----------------- include/linux/hid.h | 4 ++++ 2 files changed, 36 insertions(+), 22 deletions(-)
drivers/hid/hid-core.c +32 -22
@@ -340,7 +340,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;
@@ -349,8 +349,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;
@@ -359,6 +360,7 @@ static s32 item_sdata(struct hid_item *item) }return 0 ; } +EXPORT_SYMBOL_GPL (hid_item_sdata);/* * Process a global item.
@@ -391,29 +393,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 :
@@ -421,7 +423,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
@@ -429,11 +431,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);
@@ -442,7 +444,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);
@@ -451,7 +453,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",
@@ -476,7 +478,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 :
@@ -608,7 +610,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 :
@@ -707,12 +709,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;
@@ -773,6 +782,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) {
@@ -831,7 +841,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 :
@@ -891,7 +901,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);/*
@@ -1250,7 +1260,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 ) {
include/linux/hid.h +4 -0
@@ -898,6 +898,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);
Signature · 1 line
2.26.2
Re: [PATCH 3/5] HID: core: Export some report item parsing functions.
Quoted 3 lines · Ronald Tschalär
These are useful to drivers that need to scan or parse reports themselves.
...
drivers/hid/hid-core.c static int hid_scan_report(struct hid_device *hid)
Quoted 7 lines
drivers/hid/hid-core.c +2
-2-while ((start =fetch_item (start, end, &item)) !=NULL ) +while ((start =hid_fetch_item (start, end, &item)) !=NULL ) dispatch_type[item.type](parser, &item); -while ((next =fetch_item (start, end, &item)) !=NULL ) { +while ((next =hid_fetch_item (start, end, &item)) !=NULL ) { start = next;
I don't see the full picture, but perhaps you may also introduce for_each_hid_item() or so.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 3/5] HID: core: Export some report item parsing functions.
Quoted 12 lines · Andy Shevchenko
Quoted 3 lines · Ronald Tschalär
These are useful to drivers that need to scan or parse reports themselves.
...
Quoted 3 lines
drivers/hid/hid-core.c +1
-1-while ((start =fetch_item (start, end, &item)) !=NULL ) +while ((start =hid_fetch_item (start, end, &item)) !=NULL ) dispatch_type[item.type](parser, &item);
Quoted 6 lines
drivers/hid/hid-core.c int hid_open_report(struct hid_device *device) · line 1264
Quoted 3 lines
drivers/hid/hid-core.c +1
-1-while ((next =fetch_item (start, end, &item)) !=NULL ) { +while ((next =hid_fetch_item (start, end, &item)) !=NULL ) { start = next;I don't see the full picture, but perhaps you may also introduce
for_each_hid_item()or so.
Same here, I don't see the full picture, but I would suggest to not export those functions at all.
From 4/5, I can see that you are using them in appleib_find_collection(), which is only called by appleib_add_device(), which in turn is always called with a parsed and started HID device. Why can you not rely on the core parsing and iterate over the already parsed hid_field?
Cheers,
Benjamin
PATCH 4/5 HID: apple-ibridge: Add Apple iBridge HID driver for T1 chip.
In reply to Ronald TschalärThe iBridge device provides access to several devices, including:
- the Touch Bar
- the iSight webcam
- the light sensor
- the fingerprint sensor
This driver provides the core support for managing the iBridge device and the access to the underlying devices. In particular, the functionality for the touch bar and light sensor is exposed via USB HID interfaces, and on devices with the T1 chip one of the HID devices is used for both functions. So this driver creates virtual HID devices, one per top-level report collection on each HID device (for a total of 3 virtual HID devices). The sub-drivers then bind to these virtual HID devices.
This way the Touch Bar and ALS drivers can be kept in their own modules, while at the same time making them look very much like as if they were connected to the real HID devices. And those drivers then work (mostly) without further changes on MacBooks with the T2 chip that don't need this driver.
--- drivers/hid/Kconfig | 16 + drivers/hid/Makefile | 1 + drivers/hid/apple-ibridge.c | 682 ++++++++++++++++++++++++++++++++++++ drivers/hid/apple-ibridge.h | 15 + drivers/hid/hid-ids.h | 1 + drivers/hid/hid-quirks.c | 3 + 6 files changed, 718 insertions(+) create mode 100644 drivers/hid/apple-ibridge.c create mode 100644 drivers/hid/apple-ibridge.h
drivers/hid/Kconfig +16 -0
@@ -136,6 +136,22 @@ config HID_APPLE Say Y here if you want support for keyboards of Apple iBooks, PowerBooks, MacBooks, MacBook Pros and Apple Aluminum. +config HID_APPLE_IBRIDGE + tristate "Apple iBridge" + depends on ACPI + depends on USB_HID + depends on X86 || COMPILE_TEST + imply HID_SENSOR_HUB + imply HID_SENSOR_ALS + help + This module provides the core support for the Apple T1 chip found + on 2016 and 2017 MacBookPro's, also known as the iBridge. The drivers + for the Touch Bar (apple-touchbar) and light sensor (hid-sensor-hub + and hid-sensor-als) need to be enabled separately. + + To compile this driver as a module, choose M here: the + module will be called apple-ibridge. + config HID_APPLEIR tristate "Apple infrared receiver" depends on (USB_HID)
drivers/hid/Makefile +1 -0
@@ -26,6 +26,7 @@ obj-$(CONFIG_HID_ACCUTOUCH) += hid-accutouch.o obj-$(CONFIG_HID_ALPS) += hid-alps.o obj-$(CONFIG_HID_ACRUX) += hid-axff.o obj-$(CONFIG_HID_APPLE) += hid-apple.o +obj-$(CONFIG_HID_APPLE_IBRIDGE) += apple-ibridge.o obj-$(CONFIG_HID_APPLEIR) += hid-appleir.o obj-$(CONFIG_HID_CREATIVE_SB0540) += hid-creative-sb0540.o obj-$(CONFIG_HID_ASUS) += hid-asus.o
drivers/hid/apple-ibridge.c new file +682 -0
682 lines not on this page · raw message
drivers/hid/apple-ibridge.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Apple iBridge Driver +* +* Copyright (c) 2018 Ronald Tschalär +*/ + +#ifndef __LINUX_APPLE_IBRDIGE_H +#define __LINUX_APPLE_IBRDIGE_H + +#define USB_VENDOR_ID_LINUX_FOUNDATION 0x1d6b +#define USB_DEVICE_ID_IBRIDGE_TB 0x0301 +#define USB_DEVICE_ID_IBRIDGE_ALS 0x0302 + +#endif
drivers/hid/hid-ids.h +1 -0
@@ -172,6 +172,7 @@#define USB_DEVICE_ID_APPLE_IRCONTROL3 0x8241#define USB_DEVICE_ID_APPLE_IRCONTROL4 0x8242#define USB_DEVICE_ID_APPLE_IRCONTROL5 0x8243 +#define USB_DEVICE_ID_APPLE_IBRIDGE 0x8600#define USB_VENDOR_ID_ASUS 0x0486#define USB_DEVICE_ID_ASUS_T91MT 0x0185
drivers/hid/hid-quirks.c +3 -0
@@ -300,6 +300,9 @@ static const struct hid_device_id hid_have_special_driver[] = { { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) }, { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, #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_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) },
Signature · 1 line
2.26.2
Re: [PATCH 4/5] HID: apple-ibridge: Add Apple iBridge HID driver for T1 chip.
Quoted 15 lines · On Sat, 27 Feb 2021 17:26:42 -0800 Ronald Tschalär <[email protected]> wrote:
The iBridge device provides access to several devices, including:
- the Touch Bar
- the iSight webcam
- the light sensor
- the fingerprint sensorThis driver provides the core support for managing the iBridge device and the access to the underlying devices. In particular, the functionality for the touch bar and light sensor is exposed via USB HID interfaces, and on devices with the T1 chip one of the HID devices is used for both functions. So this driver creates virtual HID devices, one per top-level report collection on each HID device (for a total of 3 virtual HID devices). The sub-drivers then bind to these virtual HID devices.
Quoted 7 lines
This way the Touch Bar and ALS drivers can be kept in their own modules, while at the same time making them look very much like as if they were connected to the real HID devices. And those drivers then work (mostly) without further changes on MacBooks with the T2 chip that don't need this driver.
Signed-off-by Ronald Tschalär <[email protected]>
Hi Ronald.
This is far from my specialty but mostly looks sensible to me.
Just one thing stood out that I couldn't understand. See below.
Jonathan
Quoted 5 lines
new file mode 100644
index 0000000000000..5f2b71c199746drivers/hid/apple-ibridge.c new file +0
-0@@ -0,0 +1,682 @@
...
Quoted 19 lines
drivers/hid/apple-ibridge.c new file +19
-0+ +#ifdef CONFIG_PM +/** +* appleib_forward_int_op() - Forward a hid-driver callback to all drivers on +* all virtual HID devices attached to the given real HID device. +* @hdev the real hid-device +* @forward a function that calls the callback on the given driver +* @args arguments for the forward function +* +* This is for callbacks that return a status as an int. +* +* Returns: 0 on success, or the first error returned by the @forward function. +*/ +static int appleib_forward_int_op (struct hid_device *hdev, +int (*forward)(struct hid_driver *, +struct hid_device *,void *), +void *args) +{ +struct appleib_hid_dev_info *hdev_info =hid_get_drvdata (hdev);
drivers/hid/apple-ibridge.c line 174
Quoted 10 lines
drivers/hid/apple-ibridge.c new file +10
-0+struct hid_device *sub_hdev; +int rc =0 ; +int i; + +for (i =0 ; i <ARRAY_SIZE (hdev_info->sub_hdevs); i++) { + sub_hdev = hdev_info->sub_hdevs[i]; +if (sub_hdev->driver) { + rc =forward (sub_hdev->driver, sub_hdev, args); +if (rc) +break ;
return rc; here would be cleaner.
drivers/hid/apple-ibridge.c line 174
Quoted 3 lines
drivers/hid/apple-ibridge.c new file +3
-0+ } + +break ;
This is unusual. It's a for loop but as far as I can see only first iteration can ever run as we exit the loop at this break if we haven't done so earlier. What is the intent here?
Quoted 4 lines
drivers/hid/apple-ibridge.c new file +4
-0+ } + +return rc; +}
Re: [PATCH 4/5] HID: apple-ibridge: Add Apple iBridge HID driver for T1 chip.
Hi Jonathan,
Quoted 2 lines · Jonathan Cameron
On Sat, 27 Feb 2021 17:26:42 -0800
Ronald Tschal?r <[email protected]> wrote:
[snip]
Quoted 39 lines
Quoted 18 lines
drivers/hid/apple-ibridge.c new file +18
-0+#ifdef CONFIG_PM +/** +* appleib_forward_int_op() - Forward a hid-driver callback to all drivers on +* all virtual HID devices attached to the given real HID device. +* @hdev the real hid-device +* @forward a function that calls the callback on the given driver +* @args arguments for the forward function +* +* This is for callbacks that return a status as an int. +* +* Returns: 0 on success, or the first error returned by the @forward function. +*/ +static int appleib_forward_int_op (struct hid_device *hdev, +int (*forward)(struct hid_driver *, +struct hid_device *,void *), +void *args) +{ +struct appleib_hid_dev_info *hdev_info =hid_get_drvdata (hdev);drivers/hid/apple-ibridge.c line 174
Quoted 10 lines
drivers/hid/apple-ibridge.c new file +10
-0+struct hid_device *sub_hdev; +int rc =0 ; +int i; + +for (i =0 ; i <ARRAY_SIZE (hdev_info->sub_hdevs); i++) { + sub_hdev = hdev_info->sub_hdevs[i]; +if (sub_hdev->driver) { + rc =forward (sub_hdev->driver, sub_hdev, args); +if (rc) +break ;return rc; here would be cleaner.
drivers/hid/apple-ibridge.c line 174
Quoted 3 lines
drivers/hid/apple-ibridge.c new file +3
-0+ } + +break ;This is unusual. It's a for loop but as far as I can see only first iteration can ever run as we exit the loop at this break if we haven't done so earlier. What is the intent here?
Quoted 4 lines
drivers/hid/apple-ibridge.c line 181
Quoted 4 lines
drivers/hid/apple-ibridge.c new file +4
-0+ } + +return rc; +}
Ho boy, good catch! This is simply a mistake. As you say, it should (and does now) read:
for (i = 0; i < ARRAY_SIZE(hdev_info->sub_hdevs); i++) {
sub_hdev = hdev_info->sub_hdevs[i];
if (sub_hdev->driver) {
rc = forward(sub_hdev->driver, sub_hdev, args);
if (rc)
return rc;
}
}
return rc;Thanks.
Cheers,
Ronald
Re: [PATCH 4/5] HID: apple-ibridge: Add Apple iBridge HID driver for T1 chip.
In reply to Ronald TschalärQuoted 16 lines · Ronald Tschalär
The iBridge device provides access to several devices, including:
- the Touch Bar
- the iSight webcam
- the light sensor
- the fingerprint sensorThis driver provides the core support for managing the iBridge device and the access to the underlying devices. In particular, the functionality for the touch bar and light sensor is exposed via USB HID interfaces, and on devices with the T1 chip one of the HID devices is used for both functions. So this driver creates virtual HID devices, one per top-level report collection on each HID device (for a total of 3 virtual HID devices). The sub-drivers then bind to these virtual HID devices.
Quoted 5 lines
This way the Touch Bar and ALS drivers can be kept in their own modules, while at the same time making them look very much like as if they were connected to the real HID devices. And those drivers then work (mostly) without further changes on MacBooks with the T2 chip that don't need this driver.
Thanks for the contribution.
Before I'll do a full review, two concerns:
- don't do ACPI drivers, please, in the new code. Use platform driver
infrastructure for that
- dependencies (see below)
...
drivers/hid/Kconfig config HID_APPLE · line 143
Quoted 7 lines
drivers/hid/Kconfig +5
-0+config HID_APPLE_IBRIDGE + tristate "Apple iBridge" + depends on ACPI + depends on USB_HID + depends on X86 || COMPILE_TEST
I haven't found anything ACPI specific there, so this should be rather
depends on (X86 && ACPI) || COMPILE_TEST
Quoted 10 lines
drivers/hid/Kconfig +10
-0+ imply HID_SENSOR_HUB + imply HID_SENSOR_ALS + help + This module provides the core support for the Apple T1 chip found + on 2016 and 2017 MacBookPro's, also known as the iBridge. The drivers + for the Touch Bar (apple-touchbar) and light sensor (hid-sensor-hub + and hid-sensor-als) need to be enabled separately. + + To compile this driver as a module, choose M here: the + module will be called apple-ibridge.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH 5/5 HID: apple-touchbar - Add driver for the Touch Bar on MacBook Pro's.
In reply to Ronald TschalärThis driver enables basic touch bar functionality: enabling it, switching between modes on FN key press, and dimming and turning the display off/on when idle/active.
--- drivers/hid/Kconfig | 10 + drivers/hid/Makefile | 1 + drivers/hid/apple-touchbar.c | 1523 ++++++++++++++++++++++++++++++++++ 3 files changed, 1534 insertions(+) create mode 100644 drivers/hid/apple-touchbar.c
drivers/hid/Kconfig +10 -0
@@ -141,6 +141,7 @@ config HID_APPLE_IBRIDGE depends on ACPI depends on USB_HID depends on X86 || COMPILE_TEST + imply HID_APPLE_TOUCHBAR imply HID_SENSOR_HUB imply HID_SENSOR_ALS help
@@ -152,6 +153,15 @@ config HID_APPLE_IBRIDGE To compile this driver as a module, choose M here: the module will be called apple-ibridge. +config HID_APPLE_TOUCHBAR + tristate "Apple Touch Bar" + help + Say Y here if you want support for the Touch Bar on recent + MacBook Pros. + + To compile this driver as a module, choose M here: the + module will be called apple-touchbar. + config HID_APPLEIR tristate "Apple infrared receiver" depends on (USB_HID)
drivers/hid/Makefile +1 -0
@@ -27,6 +27,7 @@ obj-$(CONFIG_HID_ALPS) += hid-alps.o obj-$(CONFIG_HID_ACRUX) += hid-axff.o obj-$(CONFIG_HID_APPLE) += hid-apple.o obj-$(CONFIG_HID_APPLE_IBRIDGE) += apple-ibridge.o +obj-$(CONFIG_HID_APPLE_TOUCHBAR) += apple-touchbar.o obj-$(CONFIG_HID_APPLEIR) += hid-appleir.o obj-$(CONFIG_HID_CREATIVE_SB0540) += hid-creative-sb0540.o obj-$(CONFIG_HID_ASUS) += hid-asus.o
drivers/hid/apple-touchbar.c new file +1523 -0
1,523 lines not on this page · raw message
Signature · 1 line
2.26.2
kernel test robot
build botRe: [PATCH 5/5] HID: apple-touchbar - Add driver for the Touch Bar on MacBook Pro's.
Thank you for the patch! Yet something to improve:
Hi "Ronald,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on hid/for-next]
[also build test ERROR on iio/togreg jikos-trivial/for-next v5.11 next-20210226] [cannot apply to jikos-hid/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Ronald-Tschal-r/Touch-Bar-and-ALS-support-for-MacBook-Pro-s/20210228-093451 base: https://git.kernel.org/pub/scm/linux/kernel/git/hid/hid.git for-next config: microblaze-randconfig-r011-20210228 (attached as .config) compiler: microblaze-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/cfbb470c2977fd10aef2791b57bdfa2d95f627e0
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Ronald-Tschal-r/Touch-Bar-and-ALS-support-for-MacBook-Pro-s/20210228-093451 git checkout cfbb470c2977fd10aef2791b57bdfa2d95f627e0
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=microblaze
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
microblaze-linux-ld: drivers/hid/apple-touchbar.o: in function `appletb_clear_iface_info':
>> drivers/hid/.tmp_gl_apple-touchbar.o:(.text+0x16dc): undefined reference to `usb_put_intf' microblaze-linux-ld: drivers/hid/apple-touchbar.o: in function `appletb_send_usb_ctrl.isra.0': >> drivers/hid/.tmp_gl_apple-touchbar.o:(.text+0x1bac): undefined reference to `usb_control_msg' microblaze-linux-ld: drivers/hid/apple-touchbar.o: in function `appletb_probe': >> drivers/hid/.tmp_gl_apple-touchbar.o:(.text+0x2670): undefined reference to `usb_get_intf' microblaze-linux-ld: drivers/hid/apple-touchbar.o: in function `appletb_set_tb_worker': >> drivers/hid/.tmp_gl_apple-touchbar.o:(.text+0x3258): undefined reference to `__divdi3'
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH 5/5] HID: apple-touchbar - Add driver for the Touch Bar on MacBook Pro's.
In reply to Ronald TschalärThank you for the patch! Yet something to improve:
Hi "Ronald,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on hid/for-next]
[also build test ERROR on iio/togreg jikos-trivial/for-next v5.11 next-20210226] [cannot apply to jikos-hid/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Ronald-Tschal-r/Touch-Bar-and-ALS-support-for-MacBook-Pro-s/20210228-093451 base: https://git.kernel.org/pub/scm/linux/kernel/git/hid/hid.git for-next config: x86_64-randconfig-r015-20210228 (attached as .config) compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project e0b1df924ae06d6d88582334087d2eacc6702e8f)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# https://github.com/0day-ci/linux/commit/cfbb470c2977fd10aef2791b57bdfa2d95f627e0
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Ronald-Tschal-r/Touch-Bar-and-ALS-support-for-MacBook-Pro-s/20210228-093451 git checkout cfbb470c2977fd10aef2791b57bdfa2d95f627e0
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> ld.lld: error: undefined symbol: usb_get_intf >>> referenced by apple-touchbar.c:1088 (drivers/hid/apple-touchbar.c:1088) >>> hid/apple-touchbar.o:(appletb_probe) in archive drivers/built-in.a -- >> ld.lld: error: undefined symbol: usb_put_intf >>> referenced by apple-touchbar.c:1101 (drivers/hid/apple-touchbar.c:1101) >>> hid/apple-touchbar.o:(appletb_probe) in archive drivers/built-in.a >>> referenced by apple-touchbar.c:1101 (drivers/hid/apple-touchbar.c:1101) >>> hid/apple-touchbar.o:(appletb_remove) in archive drivers/built-in.a -- >> ld.lld: error: undefined symbol: usb_control_msg >>> referenced by apple-touchbar.c:212 (drivers/hid/apple-touchbar.c:212) >>> hid/apple-touchbar.o:(appletb_send_usb_ctrl) in archive drivers/built-in.a >>> referenced by apple-touchbar.c:212 (drivers/hid/apple-touchbar.c:212) >>> hid/apple-touchbar.o:(appletb_send_usb_ctrl) in archive drivers/built-in.a >>> referenced by apple-touchbar.c:212 (drivers/hid/apple-touchbar.c:212) >>> hid/apple-touchbar.o:(appletb_send_usb_ctrl) in archive drivers/built-in.a >>> referenced 2 more times
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH 5/5] HID: apple-touchbar - Add driver for the Touch Bar on MacBook Pro's.
In reply to Ronald TschalärThank you for the patch! Yet something to improve:
Hi "Ronald,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on hid/for-next]
[also build test ERROR on iio/togreg jikos-trivial/for-next v5.11 next-20210226] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Ronald-Tschal-r/Touch-Bar-and-ALS-support-for-MacBook-Pro-s/20210228-093451 base: https://git.kernel.org/pub/scm/linux/kernel/git/hid/hid.git for-next config: m68k-allmodconfig (attached as .config) compiler: m68k-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/cfbb470c2977fd10aef2791b57bdfa2d95f627e0
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Ronald-Tschal-r/Touch-Bar-and-ALS-support-for-MacBook-Pro-s/20210228-093451 git checkout cfbb470c2977fd10aef2791b57bdfa2d95f627e0
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=m68k
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>, old ones prefixed by <<):
>> ERROR: modpost: "__divdi3" [drivers/hid/apple-touchbar.ko] undefined!
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Quoted 9 lines · On Sat, 27 Feb 2021 17:26:38 -0800 Ronald Tschalär <[email protected]> wrote:
This patch set provides Touch Bar and ALS support on MacBook Pro's 13,*, 14,*, and 15,*.
Some time a go an earlier version of these were posted to the list; all code comments from there have been incorporated. In addition the approach has been cleaned up, especially given that we now know how the 15,* models are implemented, so that the ibridge driver is only needed for the pre-15,* models and the ALS and Touch Bar drivers work unchanged for all models.
Please keep the version numbering increasing (even if the series has been restructured like here) or at very least include a link to the archive on lore.kernel.org (I think this is the latest earlier version)
https://lore.kernel.org/linux-iio/[email protected]/
Thanks,
Jonathan
Quoted 24 lines
Ronald Tschalär (5):
HID: Recognize sensors with application collections too.
iio: hid-sensor-als: Support change sensitivity in illuminance too.
HID: core: Export some report item parsing functions.
HID: apple-ibridge: Add Apple iBridge HID driver for T1 chip.
HID: apple-touchbar - Add driver for the Touch Bar on MacBook Pro's.drivers/hid/Kconfig | 26 + drivers/hid/Makefile | 2 + drivers/hid/apple-ibridge.c | 682 +++++++++++++ drivers/hid/apple-ibridge.h | 15 + drivers/hid/apple-touchbar.c | 1523 ++++++++++++++++++++++++++++ drivers/hid/hid-core.c | 57 +- drivers/hid/hid-ids.h | 1 + drivers/hid/hid-quirks.c | 3 + drivers/hid/hid-sensor-hub.c | 6 +- drivers/iio/light/hid-sensor-als.c | 8 + include/linux/hid.h | 4 + 11 files changed, 2302 insertions(+), 25 deletions(-) create mode 100644 drivers/hid/apple-ibridge.c create mode 100644 drivers/hid/apple-ibridge.h create mode 100644 drivers/hid/apple-touchbar.c