Re: ping: [PATCH v3] HID: add vivaldi HID driver

2020-09-21 Thread Sean O'Brien
Friendly ping.


Re: [PATCH v3] HID: add vivaldi HID driver

2020-09-09 Thread Sean O'Brien
> if ((parser->global.usage_page << 16) != HID_UP_GOOGLEVENDOR)
>   return;

I'm a bit worried about adding an early return, as it may cause issues
if someone doesn't notice when adding another case. Looking at this again
I can easily remove the second line break now that I've changed the group
name.


[PATCH v3] HID: add vivaldi HID driver

2020-09-09 Thread Sean O'Brien
Add vivaldi HID driver. This driver allows us to read and report the top
row layout of keyboards which provide a vendor-defined (Google) HID
usage.

Signed-off-by: Sean O'Brien 
---

 drivers/hid/Kconfig   |   9 +++
 drivers/hid/Makefile  |   1 +
 drivers/hid/hid-core.c|   7 ++
 drivers/hid/hid-vivaldi.c | 144 ++
 include/linux/hid.h   |   2 +
 5 files changed, 163 insertions(+)
 create mode 100644 drivers/hid/hid-vivaldi.c

diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 05315b434276..612629678c84 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -397,6 +397,15 @@ config HID_GOOGLE_HAMMER
help
Say Y here if you have a Google Hammer device.
 
+config HID_VIVALDI
+   tristate "Vivaldi Keyboard"
+   depends on HID
+   help
+ Say Y here if you want to enable support for Vivaldi keyboards.
+
+ Vivaldi keyboards use a vendor-specific (Google) HID usage to report
+ how the keys in the top row are physically ordered.
+
 config HID_GT683R
tristate "MSI GT68xR LED support"
depends on LEDS_CLASS && USB_HID
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index d8ea4b8c95af..4acb583c92a6 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -50,6 +50,7 @@ obj-$(CONFIG_HID_GEMBIRD) += hid-gembird.o
 obj-$(CONFIG_HID_GFRM) += hid-gfrm.o
 obj-$(CONFIG_HID_GLORIOUS)  += hid-glorious.o
 obj-$(CONFIG_HID_GOOGLE_HAMMER)+= hid-google-hammer.o
+obj-$(CONFIG_HID_VIVALDI)  += hid-vivaldi.o
 obj-$(CONFIG_HID_GT683R)   += hid-gt683r.o
 obj-$(CONFIG_HID_GYRATION) += hid-gyration.o
 obj-$(CONFIG_HID_HOLTEK)   += hid-holtek-kbd.o
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index d2ecc9c45255..6dbd09254c44 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -814,6 +814,13 @@ static void hid_scan_collection(struct hid_parser *parser, 
unsigned type)
 
if ((parser->global.usage_page << 16) >= HID_UP_MSVENDOR)
parser->scan_flags |= HID_SCAN_FLAG_VENDOR_SPECIFIC;
+
+   if ((parser->global.usage_page << 16) == HID_UP_GOOGLEVENDOR)
+   for (i = 0; i < parser->local.usage_index; i++)
+   if (parser->local.usage[i] ==
+   (HID_UP_GOOGLEVENDOR | 0x0001))
+   parser->device->group =
+   HID_GROUP_VIVALDI;
 }
 
 static int hid_scan_main(struct hid_parser *parser, struct hid_item *item)
diff --git a/drivers/hid/hid-vivaldi.c b/drivers/hid/hid-vivaldi.c
new file mode 100644
index ..cd7ada48b1d9
--- /dev/null
+++ b/drivers/hid/hid-vivaldi.c
@@ -0,0 +1,144 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * HID support for Vivaldi Keyboard
+ *
+ * Copyright 2020 Google LLC.
+ * Author: Sean O'Brien 
+ */
+
+#include 
+#include 
+
+#define MIN_FN_ROW_KEY 1
+#define MAX_FN_ROW_KEY 24
+#define HID_VD_FN_ROW_PHYSMAP 0x0001
+#define HID_USAGE_FN_ROW_PHYSMAP (HID_UP_GOOGLEVENDOR | HID_VD_FN_ROW_PHYSMAP)
+
+static struct hid_driver hid_vivaldi;
+
+struct vivaldi_data {
+   u32 function_row_physmap[MAX_FN_ROW_KEY - MIN_FN_ROW_KEY + 1];
+   int max_function_row_key;
+};
+
+static ssize_t function_row_physmap_show(struct device *dev,
+struct device_attribute *attr,
+char *buf)
+{
+   struct hid_device *hdev = to_hid_device(dev);
+   struct vivaldi_data *drvdata = hid_get_drvdata(hdev);
+   ssize_t size = 0;
+   int i;
+
+   if (!drvdata->max_function_row_key)
+   return 0;
+
+   for (i = 0; i < drvdata->max_function_row_key; i++)
+   size += sprintf(buf + size, "%02X ",
+   drvdata->function_row_physmap[i]);
+   size += sprintf(buf + size, "\n");
+   return size;
+}
+
+DEVICE_ATTR_RO(function_row_physmap);
+static struct attribute *sysfs_attrs[] = {
+   _attr_function_row_physmap.attr,
+   NULL
+};
+
+static const struct attribute_group input_attribute_group = {
+   .attrs = sysfs_attrs
+};
+
+static int vivaldi_probe(struct hid_device *hdev,
+const struct hid_device_id *id)
+{
+   struct vivaldi_data *drvdata;
+   int ret;
+
+   drvdata = devm_kzalloc(>dev, sizeof(*drvdata), GFP_KERNEL);
+   hid_set_drvdata(hdev, drvdata);
+
+   ret = hid_parse(hdev);
+   if (ret)
+   return ret;
+
+   return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
+}
+
+static void vivaldi_feature_mapping(struct hid_device *hdev,
+   struct hid_field *field,
+   struct hid_usage *usage)
+{
+   struct vivaldi_data *drvdata = hid_get_drvdata(hdev);
+   int fn_key;
+   int 

Re: [PATCH v2] HID: google: add google vivaldi HID driver

2020-08-26 Thread Sean O'Brien
> I actually believe we should follow the standard convention here, and have
> just one hid- driver for all google products. Currently we have
> hid-google-hammer, and this would add hid-google-vivaldi. Would you (or
> Wei-Ning, CCing here) object on merging these two together?

I'm a bit reluctant to merge them.  Partly because I'm not familiar with
the hid-google-hammer driver, but mostly because this driver is intended
to handle non-google products which will use a google-defined usage code.
Perhaps I should drop "google" from the driver name?

Thanks,
Sean O'Brien


[PATCH v2] HID: google: add google vivaldi HID driver

2020-08-25 Thread Sean O'Brien
Add Google vivaldi HID driver. This driver allows us to read and report
the top row layout of keyboards which provide a vendor-defined HID
usage.

Signed-off-by: Sean O'Brien 
---

 drivers/hid/Kconfig  |   9 ++
 drivers/hid/Makefile |   1 +
 drivers/hid/hid-core.c   |   7 ++
 drivers/hid/hid-google-vivaldi.c | 144 +++
 include/linux/hid.h  |   2 +
 5 files changed, 163 insertions(+)
 create mode 100644 drivers/hid/hid-google-vivaldi.c

diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 05315b434276..b608a5b1d753 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -397,6 +397,15 @@ config HID_GOOGLE_HAMMER
help
Say Y here if you have a Google Hammer device.
 
+config HID_GOOGLE_VIVALDI
+   tristate "Google Vivaldi Keyboard"
+   depends on HID
+   help
+ Say Y here if you want to enable support for Google Vivaldi keyboards.
+
+ Vivaldi keyboards use a vendor-specific HID usage to report how the
+ keys in the top row are physically ordered.
+
 config HID_GT683R
tristate "MSI GT68xR LED support"
depends on LEDS_CLASS && USB_HID
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index d8ea4b8c95af..35ca714c7ee2 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -50,6 +50,7 @@ obj-$(CONFIG_HID_GEMBIRD) += hid-gembird.o
 obj-$(CONFIG_HID_GFRM) += hid-gfrm.o
 obj-$(CONFIG_HID_GLORIOUS)  += hid-glorious.o
 obj-$(CONFIG_HID_GOOGLE_HAMMER)+= hid-google-hammer.o
+obj-$(CONFIG_HID_GOOGLE_VIVALDI)   += hid-google-vivaldi.o
 obj-$(CONFIG_HID_GT683R)   += hid-gt683r.o
 obj-$(CONFIG_HID_GYRATION) += hid-gyration.o
 obj-$(CONFIG_HID_HOLTEK)   += hid-holtek-kbd.o
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 359616e3efbb..4df05b35b4d0 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -814,6 +814,13 @@ static void hid_scan_collection(struct hid_parser *parser, 
unsigned type)
 
if ((parser->global.usage_page << 16) >= HID_UP_MSVENDOR)
parser->scan_flags |= HID_SCAN_FLAG_VENDOR_SPECIFIC;
+
+   if ((parser->global.usage_page << 16) == HID_UP_GOOGLEVENDOR)
+   for (i = 0; i < parser->local.usage_index; i++)
+   if (parser->local.usage[i] ==
+   (HID_UP_GOOGLEVENDOR | 0x0001))
+   parser->device->group =
+   HID_GROUP_GOOGLE_VIVALDI;
 }
 
 static int hid_scan_main(struct hid_parser *parser, struct hid_item *item)
diff --git a/drivers/hid/hid-google-vivaldi.c b/drivers/hid/hid-google-vivaldi.c
new file mode 100644
index ..9165ef5e1542
--- /dev/null
+++ b/drivers/hid/hid-google-vivaldi.c
@@ -0,0 +1,144 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * HID support for Google Vivaldi Keyboard
+ *
+ * Copyright 2020 Google LLC.
+ * Author: Sean O'Brien 
+ */
+
+#include 
+#include 
+
+#define MIN_FN_ROW_KEY 1
+#define MAX_FN_ROW_KEY 24
+#define HID_VD_FN_ROW_PHYSMAP 0x0001
+#define HID_USAGE_FN_ROW_PHYSMAP (HID_UP_GOOGLEVENDOR | HID_VD_FN_ROW_PHYSMAP)
+
+static struct hid_driver hid_vivaldi;
+
+struct vivaldi_data {
+   u32 function_row_physmap[MAX_FN_ROW_KEY - MIN_FN_ROW_KEY + 1];
+   int max_function_row_key;
+};
+
+static ssize_t function_row_physmap_show(struct device *dev,
+struct device_attribute *attr,
+char *buf)
+{
+   struct hid_device *hdev = to_hid_device(dev);
+   struct vivaldi_data *drvdata = hid_get_drvdata(hdev);
+   ssize_t size = 0;
+   int i;
+
+   if (!drvdata->max_function_row_key)
+   return 0;
+
+   for (i = 0; i < drvdata->max_function_row_key; i++)
+   size += sprintf(buf + size, "%02X ",
+   drvdata->function_row_physmap[i]);
+   size += sprintf(buf + size, "\n");
+   return size;
+}
+
+DEVICE_ATTR_RO(function_row_physmap);
+static struct attribute *sysfs_attrs[] = {
+   _attr_function_row_physmap.attr,
+   NULL
+};
+
+static const struct attribute_group input_attribute_group = {
+   .attrs = sysfs_attrs
+};
+
+static int vivaldi_probe(struct hid_device *hdev,
+const struct hid_device_id *id)
+{
+   struct vivaldi_data *drvdata;
+   int ret;
+
+   drvdata = devm_kzalloc(>dev, sizeof(*drvdata), GFP_KERNEL);
+   hid_set_drvdata(hdev, drvdata);
+
+   ret = hid_parse(hdev);
+   if (ret)
+   return ret;
+
+   return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
+}
+
+static void vivaldi_feature_mapping(struct hid_device *hdev,
+   struct hid_field *field,
+   struct hid_usage *usage

[PATCH] HID: google: add google vivaldi HID driver

2020-08-17 Thread Sean O'Brien
Add Google vivaldi HID driver. This driver allows us to read and report
the top row layout of keyboards which provide a vendor-defined HID
usage.

Signed-off-by: Sean O'Brien 
---

 drivers/hid/Kconfig  |   9 ++
 drivers/hid/Makefile |   1 +
 drivers/hid/hid-core.c   |   7 ++
 drivers/hid/hid-google-vivaldi.c | 144 +++
 include/linux/hid.h  |   2 +
 5 files changed, 163 insertions(+)
 create mode 100644 drivers/hid/hid-google-vivaldi.c

diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 05315b434276..5676d4f521c9 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -397,6 +397,15 @@ config HID_GOOGLE_HAMMER
help
Say Y here if you have a Google Hammer device.
 
+config HID_GOOGLE_VIVALDI
+   tristate "Google Vivaldi Keyboard"
+   depends on HID
+   help
+   Say Y here if you want to enable support for Google vivaldi keyboards.
+
+   These are keyboards which report physical the order of consumer/action
+   keys in the top row.
+
 config HID_GT683R
tristate "MSI GT68xR LED support"
depends on LEDS_CLASS && USB_HID
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index d8ea4b8c95af..35ca714c7ee2 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -50,6 +50,7 @@ obj-$(CONFIG_HID_GEMBIRD) += hid-gembird.o
 obj-$(CONFIG_HID_GFRM) += hid-gfrm.o
 obj-$(CONFIG_HID_GLORIOUS)  += hid-glorious.o
 obj-$(CONFIG_HID_GOOGLE_HAMMER)+= hid-google-hammer.o
+obj-$(CONFIG_HID_GOOGLE_VIVALDI)   += hid-google-vivaldi.o
 obj-$(CONFIG_HID_GT683R)   += hid-gt683r.o
 obj-$(CONFIG_HID_GYRATION) += hid-gyration.o
 obj-$(CONFIG_HID_HOLTEK)   += hid-holtek-kbd.o
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 359616e3efbb..4df05b35b4d0 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -814,6 +814,13 @@ static void hid_scan_collection(struct hid_parser *parser, 
unsigned type)
 
if ((parser->global.usage_page << 16) >= HID_UP_MSVENDOR)
parser->scan_flags |= HID_SCAN_FLAG_VENDOR_SPECIFIC;
+
+   if ((parser->global.usage_page << 16) == HID_UP_GOOGLEVENDOR)
+   for (i = 0; i < parser->local.usage_index; i++)
+   if (parser->local.usage[i] ==
+   (HID_UP_GOOGLEVENDOR | 0x0001))
+   parser->device->group =
+   HID_GROUP_GOOGLE_VIVALDI;
 }
 
 static int hid_scan_main(struct hid_parser *parser, struct hid_item *item)
diff --git a/drivers/hid/hid-google-vivaldi.c b/drivers/hid/hid-google-vivaldi.c
new file mode 100644
index ..9165ef5e1542
--- /dev/null
+++ b/drivers/hid/hid-google-vivaldi.c
@@ -0,0 +1,144 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * HID support for Google Vivaldi Keyboard
+ *
+ * Copyright 2020 Google LLC.
+ * Author: Sean O'Brien 
+ */
+
+#include 
+#include 
+
+#define MIN_FN_ROW_KEY 1
+#define MAX_FN_ROW_KEY 24
+#define HID_VD_FN_ROW_PHYSMAP 0x0001
+#define HID_USAGE_FN_ROW_PHYSMAP (HID_UP_GOOGLEVENDOR | HID_VD_FN_ROW_PHYSMAP)
+
+static struct hid_driver hid_vivaldi;
+
+struct vivaldi_data {
+   u32 function_row_physmap[MAX_FN_ROW_KEY - MIN_FN_ROW_KEY + 1];
+   int max_function_row_key;
+};
+
+static ssize_t function_row_physmap_show(struct device *dev,
+struct device_attribute *attr,
+char *buf)
+{
+   struct hid_device *hdev = to_hid_device(dev);
+   struct vivaldi_data *drvdata = hid_get_drvdata(hdev);
+   ssize_t size = 0;
+   int i;
+
+   if (!drvdata->max_function_row_key)
+   return 0;
+
+   for (i = 0; i < drvdata->max_function_row_key; i++)
+   size += sprintf(buf + size, "%02X ",
+   drvdata->function_row_physmap[i]);
+   size += sprintf(buf + size, "\n");
+   return size;
+}
+
+DEVICE_ATTR_RO(function_row_physmap);
+static struct attribute *sysfs_attrs[] = {
+   _attr_function_row_physmap.attr,
+   NULL
+};
+
+static const struct attribute_group input_attribute_group = {
+   .attrs = sysfs_attrs
+};
+
+static int vivaldi_probe(struct hid_device *hdev,
+const struct hid_device_id *id)
+{
+   struct vivaldi_data *drvdata;
+   int ret;
+
+   drvdata = devm_kzalloc(>dev, sizeof(*drvdata), GFP_KERNEL);
+   hid_set_drvdata(hdev, drvdata);
+
+   ret = hid_parse(hdev);
+   if (ret)
+   return ret;
+
+   return hid_hw_start(hdev, HID_CONNECT_DEFAULT);
+}
+
+static void vivaldi_feature_mapping(struct hid_device *hdev,
+   struct hid_field *field,
+   struct hid_usage *usage)
+{
+   struct viva

Re: [PATCH v2 08/10] Input: elan_i2c - export true width/height

2019-05-28 Thread Sean O'Brien
We do still use a maxed out major axis as a signal for a palm in the touchscreen
logic, but I'm not too concerned because if that axis is maxed out, the contact
should probably be treated as a palm anyway...

I'm more concerned with this affecting our gesture detection for
touchpad. It looks
like this change would cause all contacts to reported as some percentage bigger
than they are currently. Can you give me an idea of how big that percentage is?

On Tue, May 28, 2019 at 11:13 AM Harry Cutts  wrote:
>
> On Mon, 27 May 2019 at 18:21, Dmitry Torokhov  
> wrote:
> >
> > Hi Benjamin, KT,
> >
> > On Mon, May 27, 2019 at 11:55:01AM +0800, 廖崇榮 wrote:
> > > Hi
> > >
> > > -Original Message-
> > > From: Benjamin Tissoires [mailto:benjamin.tissoi...@redhat.com]
> > > Sent: Friday, May 24, 2019 5:37 PM
> > > To: Dmitry Torokhov; KT Liao; Rob Herring; Aaron Ma; Hans de Goede
> > > Cc: open list:HID CORE LAYER; lkml; devicet...@vger.kernel.org
> > > Subject: Re: [PATCH v2 08/10] Input: elan_i2c - export true width/height
> > >
> > > On Tue, May 21, 2019 at 3:28 PM Benjamin Tissoires 
> > >  wrote:
> > > >
> > > > The width/height is actually in the same unit than X and Y. So we
> > > > should not tamper the data, but just set the proper resolution, so
> > > > that userspace can correctly detect which touch is a palm or a finger.
> > > >
> > > > Signed-off-by: Benjamin Tissoires 
> > > >
> > > > --
> > > >
> > > > new in v2
> > > > ---
> > > >  drivers/input/mouse/elan_i2c_core.c | 11 ---
> > > >  1 file changed, 4 insertions(+), 7 deletions(-)
> > > >
> > > > diff --git a/drivers/input/mouse/elan_i2c_core.c
> > > > b/drivers/input/mouse/elan_i2c_core.c
> > > > index 7ff044c6cd11..6f4feedb7765 100644
> > > > --- a/drivers/input/mouse/elan_i2c_core.c
> > > > +++ b/drivers/input/mouse/elan_i2c_core.c
> > > > @@ -45,7 +45,6 @@
> > > >  #define DRIVER_NAME"elan_i2c"
> > > >  #define ELAN_VENDOR_ID 0x04f3
> > > >  #define ETP_MAX_PRESSURE   255
> > > > -#define ETP_FWIDTH_REDUCE  90
> > > >  #define ETP_FINGER_WIDTH   15
> > > >  #define ETP_RETRY_COUNT3
> > > >
> > > > @@ -915,12 +914,8 @@ static void elan_report_contact(struct 
> > > > elan_tp_data *data,
> > > > return;
> > > > }
> > > >
> > > > -   /*
> > > > -* To avoid treating large finger as palm, let's reduce 
> > > > the
> > > > -* width x and y per trace.
> > > > -*/
> > > > -   area_x = mk_x * (data->width_x - ETP_FWIDTH_REDUCE);
> > > > -   area_y = mk_y * (data->width_y - ETP_FWIDTH_REDUCE);
> > > > +   area_x = mk_x * data->width_x;
> > > > +   area_y = mk_y * data->width_y;
> > > >
> > > > major = max(area_x, area_y);
> > > > minor = min(area_x, area_y); @@ -1123,8 +1118,10 @@
> > > > static int elan_setup_input_device(struct elan_tp_data *data)
> > > >  ETP_MAX_PRESSURE, 0, 0);
> > > > input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0,
> > > >  ETP_FINGER_WIDTH * max_width, 0, 0);
> > > > +   input_abs_set_res(input, ABS_MT_TOUCH_MAJOR, data->x_res);
> > > > input_set_abs_params(input, ABS_MT_TOUCH_MINOR, 0,
> > > >  ETP_FINGER_WIDTH * min_width, 0, 0);
> > > > +   input_abs_set_res(input, ABS_MT_TOUCH_MINOR, data->y_res);
> > >
> > > I had a chat with Peter on Wednesday, and he mentioned that this is 
> > > dangerous as Major/Minor are max/min of the width and height. And given 
> > > that we might have 2 different resolutions, we would need to do some 
> > > computation in the kernel to ensure the data is correct with respect to 
> > > the resolution.
> > >
> > > TL;DR: I don't think we should export the resolution there :(
> > >
> > > KT, should I drop the patch entirely, or is there a strong argument for 
> > > keeping the ETP_FWIDTH_REDUCE around?
> > > I suggest you apply the patch, I have no idea why ETP_FWIDTH_REDUCE 
> > > existed.
> > > Our FW team know nothing about ETP_FWIDTH_REDUCE ether.
> > >
> > > The only side effect will happen on Chromebook because such computation 
> > > have stayed in ChromeOS' kernel for four years.
> > > Chrome's finger/palm threshold may be different from other Linux 
> > > distribution.
> > > We will discuss it with Google once the patch picked by chrome and cause 
> > > something wrong.
> >
> > Chrome has logic that contact with maximum major/minor is treated as a
> > palm, so here the driver (which originally came from Chrome OS)
> > artificially reduces the contact size to ensure that palm rejection
> > logic does not trigger.
> >
> > I'm adding Harry to confirm whether we are still using this logic and to
> > see if we can adjust it to be something else.
>
> I'm not very familiar with our touchpad code, so adding Sean O'Brien, who is.


[PATCH] [v4] HID: add support for Apple Magic Trackpad 2

2018-10-02 Thread Sean O'Brien
USB device
Vendor 05ac (Apple)
Device 0265 (Magic Trackpad 2)
Bluetooth device
Vendor 004c (Apple)
Device 0265 (Magic Trackpad 2)

Add support for Apple Magic Trackpad 2 over USB and bluetooth, putting
the device in multi-touch mode.

Signed-off-by: Claudio Mettler 
Signed-off-by: Marek Wyborski 
Signed-off-by: Sean O'Brien 
---

 drivers/hid/hid-ids.h|   1 +
 drivers/hid/hid-magicmouse.c | 142 ---
 2 files changed, 132 insertions(+), 11 deletions(-)

diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 5146ee029db4..bb0cd212c7cc 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -92,6 +92,7 @@
 #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE0x0304
 #define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d
 #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD  0x030e
+#define USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 0x0265
 #define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI  0x020e
 #define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO   0x020f
 #define USB_DEVICE_ID_APPLE_GEYSER_ANSI0x0214
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index b454c4386157..1d5ea678d268 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -54,6 +54,8 @@ module_param(report_undeciphered, bool, 0644);
 MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state 
field using a MSC_RAW event");
 
 #define TRACKPAD_REPORT_ID 0x28
+#define TRACKPAD2_USB_REPORT_ID 0x02
+#define TRACKPAD2_BT_REPORT_ID 0x31
 #define MOUSE_REPORT_ID0x29
 #define DOUBLE_REPORT_ID   0xf7
 /* These definitions are not precise, but they're close enough.  (Bits
@@ -91,6 +93,17 @@ MODULE_PARM_DESC(report_undeciphered, "Report undeciphered 
multi-touch state fie
 #define TRACKPAD_RES_Y \
((TRACKPAD_MAX_Y - TRACKPAD_MIN_Y) / (TRACKPAD_DIMENSION_Y / 100))
 
+#define TRACKPAD2_DIMENSION_X (float)16000
+#define TRACKPAD2_MIN_X -3678
+#define TRACKPAD2_MAX_X 3934
+#define TRACKPAD2_RES_X \
+   ((TRACKPAD2_MAX_X - TRACKPAD2_MIN_X) / (TRACKPAD2_DIMENSION_X / 100))
+#define TRACKPAD2_DIMENSION_Y (float)11490
+#define TRACKPAD2_MIN_Y -2478
+#define TRACKPAD2_MAX_Y 2587
+#define TRACKPAD2_RES_Y \
+   ((TRACKPAD2_MAX_Y - TRACKPAD2_MIN_Y) / (TRACKPAD2_DIMENSION_Y / 100))
+
 /**
  * struct magicmouse_sc - Tracks Magic Mouse-specific data.
  * @input: Input device through which we report events.
@@ -183,6 +196,7 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
 {
struct input_dev *input = msc->input;
int id, x, y, size, orientation, touch_major, touch_minor, state, down;
+   int pressure = 0;
 
if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
id = (tdata[6] << 2 | tdata[5] >> 6) & 0xf;
@@ -194,6 +208,17 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
touch_minor = tdata[4];
state = tdata[7] & TOUCH_STATE_MASK;
down = state != TOUCH_STATE_NONE;
+   } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) {
+   id = tdata[8] & 0xf;
+   x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
+   y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19);
+   size = tdata[6];
+   orientation = (tdata[8] >> 5) - 4;
+   touch_major = tdata[4];
+   touch_minor = tdata[5];
+   pressure = tdata[7];
+   state = tdata[3] & 0xC0;
+   down = state == 0x80;
} else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
id = (tdata[7] << 2 | tdata[6] >> 6) & 0xf;
x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
@@ -215,7 +240,8 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
/* If requested, emulate a scroll wheel by detecting small
 * vertical touch motions.
 */
-   if (emulate_scroll_wheel) {
+   if (emulate_scroll_wheel && (input->id.product !=
+   USB_DEVICE_ID_APPLE_MAGICTRACKPAD2)) {
unsigned long now = jiffies;
int step_x = msc->touches[id].scroll_x - x;
int step_y = msc->touches[id].scroll_y - y;
@@ -269,10 +295,14 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
input_report_abs(input, ABS_MT_POSITION_X, x);
input_report_abs(input, ABS_MT_POSITION_Y, y);
 
+   if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2)
+   input_report_abs(input, ABS_MT_PRESSURE, pressure);
+
if (report_undeciphered) {
if (input->id.product == USB_DEVICE_ID_APPLE

[PATCH] [v4] HID: add support for Apple Magic Trackpad 2

2018-10-02 Thread Sean O'Brien
USB device
Vendor 05ac (Apple)
Device 0265 (Magic Trackpad 2)
Bluetooth device
Vendor 004c (Apple)
Device 0265 (Magic Trackpad 2)

Add support for Apple Magic Trackpad 2 over USB and bluetooth, putting
the device in multi-touch mode.

Signed-off-by: Claudio Mettler 
Signed-off-by: Marek Wyborski 
Signed-off-by: Sean O'Brien 
---

 drivers/hid/hid-ids.h|   1 +
 drivers/hid/hid-magicmouse.c | 142 ---
 2 files changed, 132 insertions(+), 11 deletions(-)

diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 5146ee029db4..bb0cd212c7cc 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -92,6 +92,7 @@
 #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE0x0304
 #define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d
 #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD  0x030e
+#define USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 0x0265
 #define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI  0x020e
 #define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO   0x020f
 #define USB_DEVICE_ID_APPLE_GEYSER_ANSI0x0214
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index b454c4386157..1d5ea678d268 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -54,6 +54,8 @@ module_param(report_undeciphered, bool, 0644);
 MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state 
field using a MSC_RAW event");
 
 #define TRACKPAD_REPORT_ID 0x28
+#define TRACKPAD2_USB_REPORT_ID 0x02
+#define TRACKPAD2_BT_REPORT_ID 0x31
 #define MOUSE_REPORT_ID0x29
 #define DOUBLE_REPORT_ID   0xf7
 /* These definitions are not precise, but they're close enough.  (Bits
@@ -91,6 +93,17 @@ MODULE_PARM_DESC(report_undeciphered, "Report undeciphered 
multi-touch state fie
 #define TRACKPAD_RES_Y \
((TRACKPAD_MAX_Y - TRACKPAD_MIN_Y) / (TRACKPAD_DIMENSION_Y / 100))
 
+#define TRACKPAD2_DIMENSION_X (float)16000
+#define TRACKPAD2_MIN_X -3678
+#define TRACKPAD2_MAX_X 3934
+#define TRACKPAD2_RES_X \
+   ((TRACKPAD2_MAX_X - TRACKPAD2_MIN_X) / (TRACKPAD2_DIMENSION_X / 100))
+#define TRACKPAD2_DIMENSION_Y (float)11490
+#define TRACKPAD2_MIN_Y -2478
+#define TRACKPAD2_MAX_Y 2587
+#define TRACKPAD2_RES_Y \
+   ((TRACKPAD2_MAX_Y - TRACKPAD2_MIN_Y) / (TRACKPAD2_DIMENSION_Y / 100))
+
 /**
  * struct magicmouse_sc - Tracks Magic Mouse-specific data.
  * @input: Input device through which we report events.
@@ -183,6 +196,7 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
 {
struct input_dev *input = msc->input;
int id, x, y, size, orientation, touch_major, touch_minor, state, down;
+   int pressure = 0;
 
if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
id = (tdata[6] << 2 | tdata[5] >> 6) & 0xf;
@@ -194,6 +208,17 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
touch_minor = tdata[4];
state = tdata[7] & TOUCH_STATE_MASK;
down = state != TOUCH_STATE_NONE;
+   } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) {
+   id = tdata[8] & 0xf;
+   x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
+   y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19);
+   size = tdata[6];
+   orientation = (tdata[8] >> 5) - 4;
+   touch_major = tdata[4];
+   touch_minor = tdata[5];
+   pressure = tdata[7];
+   state = tdata[3] & 0xC0;
+   down = state == 0x80;
} else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
id = (tdata[7] << 2 | tdata[6] >> 6) & 0xf;
x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
@@ -215,7 +240,8 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
/* If requested, emulate a scroll wheel by detecting small
 * vertical touch motions.
 */
-   if (emulate_scroll_wheel) {
+   if (emulate_scroll_wheel && (input->id.product !=
+   USB_DEVICE_ID_APPLE_MAGICTRACKPAD2)) {
unsigned long now = jiffies;
int step_x = msc->touches[id].scroll_x - x;
int step_y = msc->touches[id].scroll_y - y;
@@ -269,10 +295,14 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
input_report_abs(input, ABS_MT_POSITION_X, x);
input_report_abs(input, ABS_MT_POSITION_Y, y);
 
+   if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2)
+   input_report_abs(input, ABS_MT_PRESSURE, pressure);
+
if (report_undeciphered) {
if (input->id.product == USB_DEVICE_ID_APPLE

Re: [PATCH] [v3] HID: add support for Apple Magic Trackpad 2

2018-10-02 Thread Sean O'Brien
On Mon, Oct 1, 2018 at 1:43 AM Benjamin Tissoires
 wrote:
>
> [adding Peter, for the libinput question]
>
> On Fri, Sep 21, 2018 at 1:13 AM Sean O'Brien  wrote:
> >
> > USB device
> > Vendor 05ac (Apple)
> > Device 0265 (Magic Trackpad 2)
> > Bluetooth device
> > Vendor 004c (Apple)
> > Device 0265 (Magic Trackpad 2)
> >
> > Add support for Apple Magic Trackpad 2 over USB and bluetooth, putting
> > the device in multi-touch mode.
> >
> > Signed-off-by: Claudio Mettler 
> > Signed-off-by: Marek Wyborski 
> > Signed-off-by: Sean O'Brien 
> > ---
> >
>
> a few nitpcks:
>
> >  drivers/hid/hid-ids.h|   1 +
> >  drivers/hid/hid-magicmouse.c | 149 +++
> >  2 files changed, 134 insertions(+), 16 deletions(-)
> >
> > diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
> > index 5146ee029db4..bb0cd212c7cc 100644
> > --- a/drivers/hid/hid-ids.h
> > +++ b/drivers/hid/hid-ids.h
> > @@ -92,6 +92,7 @@
> >  #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE0x0304
> >  #define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d
> >  #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD  0x030e
> > +#define USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 0x0265
> >  #define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI  0x020e
> >  #define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO   0x020f
> >  #define USB_DEVICE_ID_APPLE_GEYSER_ANSI0x0214
> > diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
> > index b454c4386157..6a3a6c83e509 100644
> > --- a/drivers/hid/hid-magicmouse.c
> > +++ b/drivers/hid/hid-magicmouse.c
> > @@ -54,6 +54,8 @@ module_param(report_undeciphered, bool, 0644);
> >  MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch 
> > state field using a MSC_RAW event");
> >
> >  #define TRACKPAD_REPORT_ID 0x28
> > +#define TRACKPAD2_USB_REPORT_ID 0x02
> > +#define TRACKPAD2_BT_REPORT_ID 0x31
> >  #define MOUSE_REPORT_ID0x29
> >  #define DOUBLE_REPORT_ID   0xf7
> >  /* These definitions are not precise, but they're close enough.  (Bits
> > @@ -91,6 +93,17 @@ MODULE_PARM_DESC(report_undeciphered, "Report 
> > undeciphered multi-touch state fie
> >  #define TRACKPAD_RES_Y \
> > ((TRACKPAD_MAX_Y - TRACKPAD_MIN_Y) / (TRACKPAD_DIMENSION_Y / 100))
> >
> > +#define TRACKPAD2_DIMENSION_X (float)16000
> > +#define TRACKPAD2_MIN_X -3678
> > +#define TRACKPAD2_MAX_X 3934
> > +#define TRACKPAD2_RES_X \
> > +   ((TRACKPAD2_MAX_X - TRACKPAD2_MIN_X) / (TRACKPAD2_DIMENSION_X / 
> > 100))
> > +#define TRACKPAD2_DIMENSION_Y (float)11490
> > +#define TRACKPAD2_MIN_Y -2478
> > +#define TRACKPAD2_MAX_Y 2587
> > +#define TRACKPAD2_RES_Y \
> > +   ((TRACKPAD2_MAX_Y - TRACKPAD2_MIN_Y) / (TRACKPAD2_DIMENSION_Y / 
> > 100))
> > +
> >  /**
> >   * struct magicmouse_sc - Tracks Magic Mouse-specific data.
> >   * @input: Input device through which we report events.
> > @@ -183,6 +196,7 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
> > *msc, int raw_id, u8 *tda
> >  {
> > struct input_dev *input = msc->input;
> > int id, x, y, size, orientation, touch_major, touch_minor, state, 
> > down;
> > +   int pressure = 0;
> >
> > if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
> > id = (tdata[6] << 2 | tdata[5] >> 6) & 0xf;
> > @@ -194,6 +208,20 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
> > *msc, int raw_id, u8 *tda
> > touch_minor = tdata[4];
> > state = tdata[7] & TOUCH_STATE_MASK;
> > down = state != TOUCH_STATE_NONE;
> > +   } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) 
> > {
> > +   id = tdata[8] & 0xf;
> > +   x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
> > +   y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 
> > 19);
> > +   size = tdata[6];
> > +   orientation = (tdata[8] >> 5) - 4;
> > +   touch_major = tdata[4];
> > +   touch_minor = tdata[5];
> > +   /* Add to pressure to prevent libraries such as libinput
> > +* from ignoring low pressure touches
> > +*/
> > +   pressure = tdata[7] + 30;
>
> Peter, can you have a look?
>
> To me, while add

Re: [PATCH] [v3] HID: add support for Apple Magic Trackpad 2

2018-10-02 Thread Sean O'Brien
On Mon, Oct 1, 2018 at 1:43 AM Benjamin Tissoires
 wrote:
>
> [adding Peter, for the libinput question]
>
> On Fri, Sep 21, 2018 at 1:13 AM Sean O'Brien  wrote:
> >
> > USB device
> > Vendor 05ac (Apple)
> > Device 0265 (Magic Trackpad 2)
> > Bluetooth device
> > Vendor 004c (Apple)
> > Device 0265 (Magic Trackpad 2)
> >
> > Add support for Apple Magic Trackpad 2 over USB and bluetooth, putting
> > the device in multi-touch mode.
> >
> > Signed-off-by: Claudio Mettler 
> > Signed-off-by: Marek Wyborski 
> > Signed-off-by: Sean O'Brien 
> > ---
> >
>
> a few nitpcks:
>
> >  drivers/hid/hid-ids.h|   1 +
> >  drivers/hid/hid-magicmouse.c | 149 +++
> >  2 files changed, 134 insertions(+), 16 deletions(-)
> >
> > diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
> > index 5146ee029db4..bb0cd212c7cc 100644
> > --- a/drivers/hid/hid-ids.h
> > +++ b/drivers/hid/hid-ids.h
> > @@ -92,6 +92,7 @@
> >  #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE0x0304
> >  #define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d
> >  #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD  0x030e
> > +#define USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 0x0265
> >  #define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI  0x020e
> >  #define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO   0x020f
> >  #define USB_DEVICE_ID_APPLE_GEYSER_ANSI0x0214
> > diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
> > index b454c4386157..6a3a6c83e509 100644
> > --- a/drivers/hid/hid-magicmouse.c
> > +++ b/drivers/hid/hid-magicmouse.c
> > @@ -54,6 +54,8 @@ module_param(report_undeciphered, bool, 0644);
> >  MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch 
> > state field using a MSC_RAW event");
> >
> >  #define TRACKPAD_REPORT_ID 0x28
> > +#define TRACKPAD2_USB_REPORT_ID 0x02
> > +#define TRACKPAD2_BT_REPORT_ID 0x31
> >  #define MOUSE_REPORT_ID0x29
> >  #define DOUBLE_REPORT_ID   0xf7
> >  /* These definitions are not precise, but they're close enough.  (Bits
> > @@ -91,6 +93,17 @@ MODULE_PARM_DESC(report_undeciphered, "Report 
> > undeciphered multi-touch state fie
> >  #define TRACKPAD_RES_Y \
> > ((TRACKPAD_MAX_Y - TRACKPAD_MIN_Y) / (TRACKPAD_DIMENSION_Y / 100))
> >
> > +#define TRACKPAD2_DIMENSION_X (float)16000
> > +#define TRACKPAD2_MIN_X -3678
> > +#define TRACKPAD2_MAX_X 3934
> > +#define TRACKPAD2_RES_X \
> > +   ((TRACKPAD2_MAX_X - TRACKPAD2_MIN_X) / (TRACKPAD2_DIMENSION_X / 
> > 100))
> > +#define TRACKPAD2_DIMENSION_Y (float)11490
> > +#define TRACKPAD2_MIN_Y -2478
> > +#define TRACKPAD2_MAX_Y 2587
> > +#define TRACKPAD2_RES_Y \
> > +   ((TRACKPAD2_MAX_Y - TRACKPAD2_MIN_Y) / (TRACKPAD2_DIMENSION_Y / 
> > 100))
> > +
> >  /**
> >   * struct magicmouse_sc - Tracks Magic Mouse-specific data.
> >   * @input: Input device through which we report events.
> > @@ -183,6 +196,7 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
> > *msc, int raw_id, u8 *tda
> >  {
> > struct input_dev *input = msc->input;
> > int id, x, y, size, orientation, touch_major, touch_minor, state, 
> > down;
> > +   int pressure = 0;
> >
> > if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
> > id = (tdata[6] << 2 | tdata[5] >> 6) & 0xf;
> > @@ -194,6 +208,20 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
> > *msc, int raw_id, u8 *tda
> > touch_minor = tdata[4];
> > state = tdata[7] & TOUCH_STATE_MASK;
> > down = state != TOUCH_STATE_NONE;
> > +   } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) 
> > {
> > +   id = tdata[8] & 0xf;
> > +   x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
> > +   y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 
> > 19);
> > +   size = tdata[6];
> > +   orientation = (tdata[8] >> 5) - 4;
> > +   touch_major = tdata[4];
> > +   touch_minor = tdata[5];
> > +   /* Add to pressure to prevent libraries such as libinput
> > +* from ignoring low pressure touches
> > +*/
> > +   pressure = tdata[7] + 30;
>
> Peter, can you have a look?
>
> To me, while add

Re: [PATCH] [v3] HID: add support for Apple Magic Trackpad 2

2018-09-27 Thread Sean O'Brien
Gentle reminder, thank you!

On Thu, Sep 20, 2018 at 4:13 PM Sean O'Brien  wrote:
>
> USB device
> Vendor 05ac (Apple)
> Device 0265 (Magic Trackpad 2)
> Bluetooth device
> Vendor 004c (Apple)
> Device 0265 (Magic Trackpad 2)
>
> Add support for Apple Magic Trackpad 2 over USB and bluetooth, putting
> the device in multi-touch mode.
>
> Signed-off-by: Claudio Mettler 
> Signed-off-by: Marek Wyborski 
> Signed-off-by: Sean O'Brien 
> ---
>
>  drivers/hid/hid-ids.h|   1 +
>  drivers/hid/hid-magicmouse.c | 149 +++
>  2 files changed, 134 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
> index 5146ee029db4..bb0cd212c7cc 100644
> --- a/drivers/hid/hid-ids.h
> +++ b/drivers/hid/hid-ids.h
> @@ -92,6 +92,7 @@
>  #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE0x0304
>  #define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d
>  #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD  0x030e
> +#define USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 0x0265
>  #define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI  0x020e
>  #define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO   0x020f
>  #define USB_DEVICE_ID_APPLE_GEYSER_ANSI0x0214
> diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
> index b454c4386157..6a3a6c83e509 100644
> --- a/drivers/hid/hid-magicmouse.c
> +++ b/drivers/hid/hid-magicmouse.c
> @@ -54,6 +54,8 @@ module_param(report_undeciphered, bool, 0644);
>  MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state 
> field using a MSC_RAW event");
>
>  #define TRACKPAD_REPORT_ID 0x28
> +#define TRACKPAD2_USB_REPORT_ID 0x02
> +#define TRACKPAD2_BT_REPORT_ID 0x31
>  #define MOUSE_REPORT_ID0x29
>  #define DOUBLE_REPORT_ID   0xf7
>  /* These definitions are not precise, but they're close enough.  (Bits
> @@ -91,6 +93,17 @@ MODULE_PARM_DESC(report_undeciphered, "Report undeciphered 
> multi-touch state fie
>  #define TRACKPAD_RES_Y \
> ((TRACKPAD_MAX_Y - TRACKPAD_MIN_Y) / (TRACKPAD_DIMENSION_Y / 100))
>
> +#define TRACKPAD2_DIMENSION_X (float)16000
> +#define TRACKPAD2_MIN_X -3678
> +#define TRACKPAD2_MAX_X 3934
> +#define TRACKPAD2_RES_X \
> +   ((TRACKPAD2_MAX_X - TRACKPAD2_MIN_X) / (TRACKPAD2_DIMENSION_X / 100))
> +#define TRACKPAD2_DIMENSION_Y (float)11490
> +#define TRACKPAD2_MIN_Y -2478
> +#define TRACKPAD2_MAX_Y 2587
> +#define TRACKPAD2_RES_Y \
> +   ((TRACKPAD2_MAX_Y - TRACKPAD2_MIN_Y) / (TRACKPAD2_DIMENSION_Y / 100))
> +
>  /**
>   * struct magicmouse_sc - Tracks Magic Mouse-specific data.
>   * @input: Input device through which we report events.
> @@ -183,6 +196,7 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
> *msc, int raw_id, u8 *tda
>  {
> struct input_dev *input = msc->input;
> int id, x, y, size, orientation, touch_major, touch_minor, state, 
> down;
> +   int pressure = 0;
>
> if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
> id = (tdata[6] << 2 | tdata[5] >> 6) & 0xf;
> @@ -194,6 +208,20 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
> *msc, int raw_id, u8 *tda
> touch_minor = tdata[4];
> state = tdata[7] & TOUCH_STATE_MASK;
> down = state != TOUCH_STATE_NONE;
> +   } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) {
> +   id = tdata[8] & 0xf;
> +   x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
> +   y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 
> 19);
> +   size = tdata[6];
> +   orientation = (tdata[8] >> 5) - 4;
> +   touch_major = tdata[4];
> +   touch_minor = tdata[5];
> +   /* Add to pressure to prevent libraries such as libinput
> +* from ignoring low pressure touches
> +*/
> +   pressure = tdata[7] + 30;
> +   state = tdata[3] & 0xC0;
> +   down = state == 0x80;
> } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
> id = (tdata[7] << 2 | tdata[6] >> 6) & 0xf;
> x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
> @@ -215,7 +243,8 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
> *msc, int raw_id, u8 *tda
> /* If requested, emulate a scroll wheel by detecting small
>  * vertical touch motions.
>  */
> -   if (emulate_scroll_wheel) {
> +   if (emulate_scroll_wheel && (input->id.product !=
> + 

Re: [PATCH] [v3] HID: add support for Apple Magic Trackpad 2

2018-09-27 Thread Sean O'Brien
Gentle reminder, thank you!

On Thu, Sep 20, 2018 at 4:13 PM Sean O'Brien  wrote:
>
> USB device
> Vendor 05ac (Apple)
> Device 0265 (Magic Trackpad 2)
> Bluetooth device
> Vendor 004c (Apple)
> Device 0265 (Magic Trackpad 2)
>
> Add support for Apple Magic Trackpad 2 over USB and bluetooth, putting
> the device in multi-touch mode.
>
> Signed-off-by: Claudio Mettler 
> Signed-off-by: Marek Wyborski 
> Signed-off-by: Sean O'Brien 
> ---
>
>  drivers/hid/hid-ids.h|   1 +
>  drivers/hid/hid-magicmouse.c | 149 +++
>  2 files changed, 134 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
> index 5146ee029db4..bb0cd212c7cc 100644
> --- a/drivers/hid/hid-ids.h
> +++ b/drivers/hid/hid-ids.h
> @@ -92,6 +92,7 @@
>  #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE0x0304
>  #define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d
>  #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD  0x030e
> +#define USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 0x0265
>  #define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI  0x020e
>  #define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO   0x020f
>  #define USB_DEVICE_ID_APPLE_GEYSER_ANSI0x0214
> diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
> index b454c4386157..6a3a6c83e509 100644
> --- a/drivers/hid/hid-magicmouse.c
> +++ b/drivers/hid/hid-magicmouse.c
> @@ -54,6 +54,8 @@ module_param(report_undeciphered, bool, 0644);
>  MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state 
> field using a MSC_RAW event");
>
>  #define TRACKPAD_REPORT_ID 0x28
> +#define TRACKPAD2_USB_REPORT_ID 0x02
> +#define TRACKPAD2_BT_REPORT_ID 0x31
>  #define MOUSE_REPORT_ID0x29
>  #define DOUBLE_REPORT_ID   0xf7
>  /* These definitions are not precise, but they're close enough.  (Bits
> @@ -91,6 +93,17 @@ MODULE_PARM_DESC(report_undeciphered, "Report undeciphered 
> multi-touch state fie
>  #define TRACKPAD_RES_Y \
> ((TRACKPAD_MAX_Y - TRACKPAD_MIN_Y) / (TRACKPAD_DIMENSION_Y / 100))
>
> +#define TRACKPAD2_DIMENSION_X (float)16000
> +#define TRACKPAD2_MIN_X -3678
> +#define TRACKPAD2_MAX_X 3934
> +#define TRACKPAD2_RES_X \
> +   ((TRACKPAD2_MAX_X - TRACKPAD2_MIN_X) / (TRACKPAD2_DIMENSION_X / 100))
> +#define TRACKPAD2_DIMENSION_Y (float)11490
> +#define TRACKPAD2_MIN_Y -2478
> +#define TRACKPAD2_MAX_Y 2587
> +#define TRACKPAD2_RES_Y \
> +   ((TRACKPAD2_MAX_Y - TRACKPAD2_MIN_Y) / (TRACKPAD2_DIMENSION_Y / 100))
> +
>  /**
>   * struct magicmouse_sc - Tracks Magic Mouse-specific data.
>   * @input: Input device through which we report events.
> @@ -183,6 +196,7 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
> *msc, int raw_id, u8 *tda
>  {
> struct input_dev *input = msc->input;
> int id, x, y, size, orientation, touch_major, touch_minor, state, 
> down;
> +   int pressure = 0;
>
> if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
> id = (tdata[6] << 2 | tdata[5] >> 6) & 0xf;
> @@ -194,6 +208,20 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
> *msc, int raw_id, u8 *tda
> touch_minor = tdata[4];
> state = tdata[7] & TOUCH_STATE_MASK;
> down = state != TOUCH_STATE_NONE;
> +   } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) {
> +   id = tdata[8] & 0xf;
> +   x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
> +   y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 
> 19);
> +   size = tdata[6];
> +   orientation = (tdata[8] >> 5) - 4;
> +   touch_major = tdata[4];
> +   touch_minor = tdata[5];
> +   /* Add to pressure to prevent libraries such as libinput
> +* from ignoring low pressure touches
> +*/
> +   pressure = tdata[7] + 30;
> +   state = tdata[3] & 0xC0;
> +   down = state == 0x80;
> } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
> id = (tdata[7] << 2 | tdata[6] >> 6) & 0xf;
> x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
> @@ -215,7 +243,8 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
> *msc, int raw_id, u8 *tda
> /* If requested, emulate a scroll wheel by detecting small
>  * vertical touch motions.
>  */
> -   if (emulate_scroll_wheel) {
> +   if (emulate_scroll_wheel && (input->id.product !=
> + 

[PATCH] [v3] HID: add support for Apple Magic Trackpad 2

2018-09-20 Thread Sean O'Brien
USB device
Vendor 05ac (Apple)
Device 0265 (Magic Trackpad 2)
Bluetooth device
Vendor 004c (Apple)
Device 0265 (Magic Trackpad 2)

Add support for Apple Magic Trackpad 2 over USB and bluetooth, putting
the device in multi-touch mode.

Signed-off-by: Claudio Mettler 
Signed-off-by: Marek Wyborski 
Signed-off-by: Sean O'Brien 
---

 drivers/hid/hid-ids.h|   1 +
 drivers/hid/hid-magicmouse.c | 149 +++
 2 files changed, 134 insertions(+), 16 deletions(-)

diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 5146ee029db4..bb0cd212c7cc 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -92,6 +92,7 @@
 #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE0x0304
 #define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d
 #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD  0x030e
+#define USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 0x0265
 #define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI  0x020e
 #define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO   0x020f
 #define USB_DEVICE_ID_APPLE_GEYSER_ANSI0x0214
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index b454c4386157..6a3a6c83e509 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -54,6 +54,8 @@ module_param(report_undeciphered, bool, 0644);
 MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state 
field using a MSC_RAW event");
 
 #define TRACKPAD_REPORT_ID 0x28
+#define TRACKPAD2_USB_REPORT_ID 0x02
+#define TRACKPAD2_BT_REPORT_ID 0x31
 #define MOUSE_REPORT_ID0x29
 #define DOUBLE_REPORT_ID   0xf7
 /* These definitions are not precise, but they're close enough.  (Bits
@@ -91,6 +93,17 @@ MODULE_PARM_DESC(report_undeciphered, "Report undeciphered 
multi-touch state fie
 #define TRACKPAD_RES_Y \
((TRACKPAD_MAX_Y - TRACKPAD_MIN_Y) / (TRACKPAD_DIMENSION_Y / 100))
 
+#define TRACKPAD2_DIMENSION_X (float)16000
+#define TRACKPAD2_MIN_X -3678
+#define TRACKPAD2_MAX_X 3934
+#define TRACKPAD2_RES_X \
+   ((TRACKPAD2_MAX_X - TRACKPAD2_MIN_X) / (TRACKPAD2_DIMENSION_X / 100))
+#define TRACKPAD2_DIMENSION_Y (float)11490
+#define TRACKPAD2_MIN_Y -2478
+#define TRACKPAD2_MAX_Y 2587
+#define TRACKPAD2_RES_Y \
+   ((TRACKPAD2_MAX_Y - TRACKPAD2_MIN_Y) / (TRACKPAD2_DIMENSION_Y / 100))
+
 /**
  * struct magicmouse_sc - Tracks Magic Mouse-specific data.
  * @input: Input device through which we report events.
@@ -183,6 +196,7 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
 {
struct input_dev *input = msc->input;
int id, x, y, size, orientation, touch_major, touch_minor, state, down;
+   int pressure = 0;
 
if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
id = (tdata[6] << 2 | tdata[5] >> 6) & 0xf;
@@ -194,6 +208,20 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
touch_minor = tdata[4];
state = tdata[7] & TOUCH_STATE_MASK;
down = state != TOUCH_STATE_NONE;
+   } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) {
+   id = tdata[8] & 0xf;
+   x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
+   y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19);
+   size = tdata[6];
+   orientation = (tdata[8] >> 5) - 4;
+   touch_major = tdata[4];
+   touch_minor = tdata[5];
+   /* Add to pressure to prevent libraries such as libinput
+* from ignoring low pressure touches
+*/
+   pressure = tdata[7] + 30;
+   state = tdata[3] & 0xC0;
+   down = state == 0x80;
} else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
id = (tdata[7] << 2 | tdata[6] >> 6) & 0xf;
x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
@@ -215,7 +243,8 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
/* If requested, emulate a scroll wheel by detecting small
 * vertical touch motions.
 */
-   if (emulate_scroll_wheel) {
+   if (emulate_scroll_wheel && (input->id.product !=
+   USB_DEVICE_ID_APPLE_MAGICTRACKPAD2)) {
unsigned long now = jiffies;
int step_x = msc->touches[id].scroll_x - x;
int step_y = msc->touches[id].scroll_y - y;
@@ -269,10 +298,14 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
input_report_abs(input, ABS_MT_POSITION_X, x);
input_report_abs(input, ABS_MT_POSITION_Y, y);
 
+   if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2)
+   input_report_abs(input

[PATCH] [v3] HID: add support for Apple Magic Trackpad 2

2018-09-20 Thread Sean O'Brien
USB device
Vendor 05ac (Apple)
Device 0265 (Magic Trackpad 2)
Bluetooth device
Vendor 004c (Apple)
Device 0265 (Magic Trackpad 2)

Add support for Apple Magic Trackpad 2 over USB and bluetooth, putting
the device in multi-touch mode.

Signed-off-by: Claudio Mettler 
Signed-off-by: Marek Wyborski 
Signed-off-by: Sean O'Brien 
---

 drivers/hid/hid-ids.h|   1 +
 drivers/hid/hid-magicmouse.c | 149 +++
 2 files changed, 134 insertions(+), 16 deletions(-)

diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 5146ee029db4..bb0cd212c7cc 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -92,6 +92,7 @@
 #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE0x0304
 #define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d
 #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD  0x030e
+#define USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 0x0265
 #define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI  0x020e
 #define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO   0x020f
 #define USB_DEVICE_ID_APPLE_GEYSER_ANSI0x0214
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index b454c4386157..6a3a6c83e509 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -54,6 +54,8 @@ module_param(report_undeciphered, bool, 0644);
 MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state 
field using a MSC_RAW event");
 
 #define TRACKPAD_REPORT_ID 0x28
+#define TRACKPAD2_USB_REPORT_ID 0x02
+#define TRACKPAD2_BT_REPORT_ID 0x31
 #define MOUSE_REPORT_ID0x29
 #define DOUBLE_REPORT_ID   0xf7
 /* These definitions are not precise, but they're close enough.  (Bits
@@ -91,6 +93,17 @@ MODULE_PARM_DESC(report_undeciphered, "Report undeciphered 
multi-touch state fie
 #define TRACKPAD_RES_Y \
((TRACKPAD_MAX_Y - TRACKPAD_MIN_Y) / (TRACKPAD_DIMENSION_Y / 100))
 
+#define TRACKPAD2_DIMENSION_X (float)16000
+#define TRACKPAD2_MIN_X -3678
+#define TRACKPAD2_MAX_X 3934
+#define TRACKPAD2_RES_X \
+   ((TRACKPAD2_MAX_X - TRACKPAD2_MIN_X) / (TRACKPAD2_DIMENSION_X / 100))
+#define TRACKPAD2_DIMENSION_Y (float)11490
+#define TRACKPAD2_MIN_Y -2478
+#define TRACKPAD2_MAX_Y 2587
+#define TRACKPAD2_RES_Y \
+   ((TRACKPAD2_MAX_Y - TRACKPAD2_MIN_Y) / (TRACKPAD2_DIMENSION_Y / 100))
+
 /**
  * struct magicmouse_sc - Tracks Magic Mouse-specific data.
  * @input: Input device through which we report events.
@@ -183,6 +196,7 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
 {
struct input_dev *input = msc->input;
int id, x, y, size, orientation, touch_major, touch_minor, state, down;
+   int pressure = 0;
 
if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
id = (tdata[6] << 2 | tdata[5] >> 6) & 0xf;
@@ -194,6 +208,20 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
touch_minor = tdata[4];
state = tdata[7] & TOUCH_STATE_MASK;
down = state != TOUCH_STATE_NONE;
+   } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2) {
+   id = tdata[8] & 0xf;
+   x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
+   y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19);
+   size = tdata[6];
+   orientation = (tdata[8] >> 5) - 4;
+   touch_major = tdata[4];
+   touch_minor = tdata[5];
+   /* Add to pressure to prevent libraries such as libinput
+* from ignoring low pressure touches
+*/
+   pressure = tdata[7] + 30;
+   state = tdata[3] & 0xC0;
+   down = state == 0x80;
} else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
id = (tdata[7] << 2 | tdata[6] >> 6) & 0xf;
x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
@@ -215,7 +243,8 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
/* If requested, emulate a scroll wheel by detecting small
 * vertical touch motions.
 */
-   if (emulate_scroll_wheel) {
+   if (emulate_scroll_wheel && (input->id.product !=
+   USB_DEVICE_ID_APPLE_MAGICTRACKPAD2)) {
unsigned long now = jiffies;
int step_x = msc->touches[id].scroll_x - x;
int step_y = msc->touches[id].scroll_y - y;
@@ -269,10 +298,14 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
input_report_abs(input, ABS_MT_POSITION_X, x);
input_report_abs(input, ABS_MT_POSITION_Y, y);
 
+   if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD2)
+   input_report_abs(input

[PATCH] [v2] HID: add support for Apple Magic Trackpad 2

2018-08-28 Thread Sean O'Brien
USB device
Vendor 05ac (Apple)
Device 0265 (Magic Trackpad 2)
Bluetooth device
Vendor 004c (Apple)
Device 0265 (Magic Trackpad 2)

Add support for Apple Magic Trackpad 2 over USB and bluetooth, putting
the device in multi-touch mode.

Signed-off-by: Claudio Mettler 
Signed-off-by: Marek Wyborski 
Signed-off-by: Sean O'Brien 
---

 drivers/hid/hid-ids.h|   2 +
 drivers/hid/hid-magicmouse.c | 184 ---
 2 files changed, 149 insertions(+), 37 deletions(-)

diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 79bdf0c7e351..d6d0b20cc015 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -88,9 +88,11 @@
 #define USB_DEVICE_ID_ANTON_TOUCH_PAD  0x3101
 
 #define USB_VENDOR_ID_APPLE0x05ac
+#define BT_VENDOR_ID_APPLE 0x004c
 #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE0x0304
 #define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d
 #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD  0x030e
+#define USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 0x0265
 #define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI  0x020e
 #define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO   0x020f
 #define USB_DEVICE_ID_APPLE_GEYSER_ANSI0x0214
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index b454c4386157..7f14866ea3c7 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -54,6 +54,8 @@ module_param(report_undeciphered, bool, 0644);
 MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state 
field using a MSC_RAW event");
 
 #define TRACKPAD_REPORT_ID 0x28
+#define TRACKPAD2_USB_REPORT_ID 0x02
+#define TRACKPAD2_BT_REPORT_ID 0x31
 #define MOUSE_REPORT_ID0x29
 #define DOUBLE_REPORT_ID   0xf7
 /* These definitions are not precise, but they're close enough.  (Bits
@@ -91,6 +93,19 @@ MODULE_PARM_DESC(report_undeciphered, "Report undeciphered 
multi-touch state fie
 #define TRACKPAD_RES_Y \
((TRACKPAD_MAX_Y - TRACKPAD_MIN_Y) / (TRACKPAD_DIMENSION_Y / 100))
 
+#define TRACKPAD2_DIMENSION_X (float)16000
+#define TRACKPAD2_MIN_X -3678
+#define TRACKPAD2_MAX_X 3934
+#define TRACKPAD2_RES_X \
+   ((TRACKPAD2_MAX_X - TRACKPAD2_MIN_X) / (TRACKPAD2_DIMENSION_X / 100))
+#define TRACKPAD2_DIMENSION_Y (float)11490
+#define TRACKPAD2_MIN_Y -2478
+#define TRACKPAD2_MAX_Y 2587
+#define TRACKPAD2_RES_Y \
+   ((TRACKPAD2_MAX_Y - TRACKPAD2_MIN_Y) / (TRACKPAD2_DIMENSION_Y / 100))
+
+#define MAX_TOUCHES16
+
 /**
  * struct magicmouse_sc - Tracks Magic Mouse-specific data.
  * @input: Input device through which we report events.
@@ -115,8 +130,8 @@ struct magicmouse_sc {
short scroll_x;
short scroll_y;
u8 size;
-   } touches[16];
-   int tracking_ids[16];
+   } touches[MAX_TOUCHES];
+   int tracking_ids[MAX_TOUCHES];
 };
 
 static int magicmouse_firm_touch(struct magicmouse_sc *msc)
@@ -183,6 +198,7 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
 {
struct input_dev *input = msc->input;
int id, x, y, size, orientation, touch_major, touch_minor, state, down;
+   int pressure = 0;
 
if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
id = (tdata[6] << 2 | tdata[5] >> 6) & 0xf;
@@ -194,7 +210,7 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
touch_minor = tdata[4];
state = tdata[7] & TOUCH_STATE_MASK;
down = state != TOUCH_STATE_NONE;
-   } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
+   } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD) {
id = (tdata[7] << 2 | tdata[6] >> 6) & 0xf;
x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19);
@@ -204,6 +220,18 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
touch_minor = tdata[5];
state = tdata[8] & TOUCH_STATE_MASK;
down = state != TOUCH_STATE_NONE;
+   } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 */
+   id = tdata[8] & 0xf;
+   x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
+   y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19);
+   size = tdata[6];
+   orientation = (tdata[8] >> 5) - 4;
+   touch_major = tdata[4];
+   touch_minor = tdata[5];
+   /* Prevent zero and low pressure values */
+   pressure = tdata[7] + 30;
+   state = tdata[3] & 0xC0;
+   down = state == 0x80;
}
 
/* Store tracking ID and other fields. */
@@ -215,7 +243,8 @@ static void magicmou

[PATCH] [v2] HID: add support for Apple Magic Trackpad 2

2018-08-28 Thread Sean O'Brien
USB device
Vendor 05ac (Apple)
Device 0265 (Magic Trackpad 2)
Bluetooth device
Vendor 004c (Apple)
Device 0265 (Magic Trackpad 2)

Add support for Apple Magic Trackpad 2 over USB and bluetooth, putting
the device in multi-touch mode.

Signed-off-by: Claudio Mettler 
Signed-off-by: Marek Wyborski 
Signed-off-by: Sean O'Brien 
---

 drivers/hid/hid-ids.h|   2 +
 drivers/hid/hid-magicmouse.c | 184 ---
 2 files changed, 149 insertions(+), 37 deletions(-)

diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 79bdf0c7e351..d6d0b20cc015 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -88,9 +88,11 @@
 #define USB_DEVICE_ID_ANTON_TOUCH_PAD  0x3101
 
 #define USB_VENDOR_ID_APPLE0x05ac
+#define BT_VENDOR_ID_APPLE 0x004c
 #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE0x0304
 #define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d
 #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD  0x030e
+#define USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 0x0265
 #define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI  0x020e
 #define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO   0x020f
 #define USB_DEVICE_ID_APPLE_GEYSER_ANSI0x0214
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index b454c4386157..7f14866ea3c7 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -54,6 +54,8 @@ module_param(report_undeciphered, bool, 0644);
 MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state 
field using a MSC_RAW event");
 
 #define TRACKPAD_REPORT_ID 0x28
+#define TRACKPAD2_USB_REPORT_ID 0x02
+#define TRACKPAD2_BT_REPORT_ID 0x31
 #define MOUSE_REPORT_ID0x29
 #define DOUBLE_REPORT_ID   0xf7
 /* These definitions are not precise, but they're close enough.  (Bits
@@ -91,6 +93,19 @@ MODULE_PARM_DESC(report_undeciphered, "Report undeciphered 
multi-touch state fie
 #define TRACKPAD_RES_Y \
((TRACKPAD_MAX_Y - TRACKPAD_MIN_Y) / (TRACKPAD_DIMENSION_Y / 100))
 
+#define TRACKPAD2_DIMENSION_X (float)16000
+#define TRACKPAD2_MIN_X -3678
+#define TRACKPAD2_MAX_X 3934
+#define TRACKPAD2_RES_X \
+   ((TRACKPAD2_MAX_X - TRACKPAD2_MIN_X) / (TRACKPAD2_DIMENSION_X / 100))
+#define TRACKPAD2_DIMENSION_Y (float)11490
+#define TRACKPAD2_MIN_Y -2478
+#define TRACKPAD2_MAX_Y 2587
+#define TRACKPAD2_RES_Y \
+   ((TRACKPAD2_MAX_Y - TRACKPAD2_MIN_Y) / (TRACKPAD2_DIMENSION_Y / 100))
+
+#define MAX_TOUCHES16
+
 /**
  * struct magicmouse_sc - Tracks Magic Mouse-specific data.
  * @input: Input device through which we report events.
@@ -115,8 +130,8 @@ struct magicmouse_sc {
short scroll_x;
short scroll_y;
u8 size;
-   } touches[16];
-   int tracking_ids[16];
+   } touches[MAX_TOUCHES];
+   int tracking_ids[MAX_TOUCHES];
 };
 
 static int magicmouse_firm_touch(struct magicmouse_sc *msc)
@@ -183,6 +198,7 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
 {
struct input_dev *input = msc->input;
int id, x, y, size, orientation, touch_major, touch_minor, state, down;
+   int pressure = 0;
 
if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
id = (tdata[6] << 2 | tdata[5] >> 6) & 0xf;
@@ -194,7 +210,7 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
touch_minor = tdata[4];
state = tdata[7] & TOUCH_STATE_MASK;
down = state != TOUCH_STATE_NONE;
-   } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
+   } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD) {
id = (tdata[7] << 2 | tdata[6] >> 6) & 0xf;
x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19);
@@ -204,6 +220,18 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
touch_minor = tdata[5];
state = tdata[8] & TOUCH_STATE_MASK;
down = state != TOUCH_STATE_NONE;
+   } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 */
+   id = tdata[8] & 0xf;
+   x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
+   y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19);
+   size = tdata[6];
+   orientation = (tdata[8] >> 5) - 4;
+   touch_major = tdata[4];
+   touch_minor = tdata[5];
+   /* Prevent zero and low pressure values */
+   pressure = tdata[7] + 30;
+   state = tdata[3] & 0xC0;
+   down = state == 0x80;
}
 
/* Store tracking ID and other fields. */
@@ -215,7 +243,8 @@ static void magicmou

[PATCH] HID: add support for Apple Magic Trackpad 2

2018-08-27 Thread Sean O'Brien
USB device
Vendor 05ac (Apple)
Device 0265 (Magic Trackpad 2)
Bluetooth device
Vendor 004c (Apple)
Device 0265 (Magic Trackpad 2)

Add support for Apple Magic Trackpad 2 over USB and bluetooth, putting
the device in multi-touch mode.

Signed-off-by: Claudio Mettler 
Signed-off-by: Marek Wyborski 
Signed-off-by: Sean O'Brien 
---

 drivers/hid/hid-ids.h|   2 +
 drivers/hid/hid-magicmouse.c | 187 ---
 2 files changed, 152 insertions(+), 37 deletions(-)

diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 79bdf0c7e351..d6d0b20cc015 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -88,9 +88,11 @@
 #define USB_DEVICE_ID_ANTON_TOUCH_PAD  0x3101
 
 #define USB_VENDOR_ID_APPLE0x05ac
+#define BT_VENDOR_ID_APPLE 0x004c
 #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE0x0304
 #define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d
 #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD  0x030e
+#define USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 0x0265
 #define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI  0x020e
 #define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO   0x020f
 #define USB_DEVICE_ID_APPLE_GEYSER_ANSI0x0214
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index b454c4386157..34152d2d2221 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "hid-ids.h"
 
@@ -54,6 +55,8 @@ module_param(report_undeciphered, bool, 0644);
 MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state 
field using a MSC_RAW event");
 
 #define TRACKPAD_REPORT_ID 0x28
+#define TRACKPAD2_USB_REPORT_ID 0x02
+#define TRACKPAD2_BT_REPORT_ID 0x31
 #define MOUSE_REPORT_ID0x29
 #define DOUBLE_REPORT_ID   0xf7
 /* These definitions are not precise, but they're close enough.  (Bits
@@ -91,6 +94,19 @@ MODULE_PARM_DESC(report_undeciphered, "Report undeciphered 
multi-touch state fie
 #define TRACKPAD_RES_Y \
((TRACKPAD_MAX_Y - TRACKPAD_MIN_Y) / (TRACKPAD_DIMENSION_Y / 100))
 
+#define TRACKPAD2_DIMENSION_X (float)16000
+#define TRACKPAD2_MIN_X -3678
+#define TRACKPAD2_MAX_X 3934
+#define TRACKPAD2_RES_X \
+   ((TRACKPAD2_MAX_X - TRACKPAD2_MIN_X) / (TRACKPAD2_DIMENSION_X / 100))
+#define TRACKPAD2_DIMENSION_Y (float)11490
+#define TRACKPAD2_MIN_Y -2478
+#define TRACKPAD2_MAX_Y 2587
+#define TRACKPAD2_RES_Y \
+   ((TRACKPAD2_MAX_Y - TRACKPAD2_MIN_Y) / (TRACKPAD2_DIMENSION_Y / 100))
+
+#define MAX_TOUCHES16
+
 /**
  * struct magicmouse_sc - Tracks Magic Mouse-specific data.
  * @input: Input device through which we report events.
@@ -115,8 +131,8 @@ struct magicmouse_sc {
short scroll_x;
short scroll_y;
u8 size;
-   } touches[16];
-   int tracking_ids[16];
+   } touches[MAX_TOUCHES];
+   int tracking_ids[MAX_TOUCHES];
 };
 
 static int magicmouse_firm_touch(struct magicmouse_sc *msc)
@@ -183,6 +199,7 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
 {
struct input_dev *input = msc->input;
int id, x, y, size, orientation, touch_major, touch_minor, state, down;
+   int pressure = 0;
 
if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
id = (tdata[6] << 2 | tdata[5] >> 6) & 0xf;
@@ -194,7 +211,7 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
touch_minor = tdata[4];
state = tdata[7] & TOUCH_STATE_MASK;
down = state != TOUCH_STATE_NONE;
-   } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
+   } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD) {
id = (tdata[7] << 2 | tdata[6] >> 6) & 0xf;
x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19);
@@ -204,6 +221,17 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
touch_minor = tdata[5];
state = tdata[8] & TOUCH_STATE_MASK;
down = state != TOUCH_STATE_NONE;
+   } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 */
+   id = tdata[8] & 0xf;
+   x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
+   y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19);
+   size = tdata[6];
+   orientation = (tdata[8] >> 5) - 4;
+   touch_major = tdata[4];
+   touch_minor = tdata[5];
+   pressure = tdata[7];
+   state = tdata[3] & 0xC0;
+   down = state == 0x80;
}
 
/* Store tracking ID and other fields.

[PATCH] HID: add support for Apple Magic Trackpad 2

2018-08-27 Thread Sean O'Brien
USB device
Vendor 05ac (Apple)
Device 0265 (Magic Trackpad 2)
Bluetooth device
Vendor 004c (Apple)
Device 0265 (Magic Trackpad 2)

Add support for Apple Magic Trackpad 2 over USB and bluetooth, putting
the device in multi-touch mode.

Signed-off-by: Claudio Mettler 
Signed-off-by: Marek Wyborski 
Signed-off-by: Sean O'Brien 
---

 drivers/hid/hid-ids.h|   2 +
 drivers/hid/hid-magicmouse.c | 187 ---
 2 files changed, 152 insertions(+), 37 deletions(-)

diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 79bdf0c7e351..d6d0b20cc015 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -88,9 +88,11 @@
 #define USB_DEVICE_ID_ANTON_TOUCH_PAD  0x3101
 
 #define USB_VENDOR_ID_APPLE0x05ac
+#define BT_VENDOR_ID_APPLE 0x004c
 #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE0x0304
 #define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d
 #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD  0x030e
+#define USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 0x0265
 #define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI  0x020e
 #define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO   0x020f
 #define USB_DEVICE_ID_APPLE_GEYSER_ANSI0x0214
diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index b454c4386157..34152d2d2221 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "hid-ids.h"
 
@@ -54,6 +55,8 @@ module_param(report_undeciphered, bool, 0644);
 MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state 
field using a MSC_RAW event");
 
 #define TRACKPAD_REPORT_ID 0x28
+#define TRACKPAD2_USB_REPORT_ID 0x02
+#define TRACKPAD2_BT_REPORT_ID 0x31
 #define MOUSE_REPORT_ID0x29
 #define DOUBLE_REPORT_ID   0xf7
 /* These definitions are not precise, but they're close enough.  (Bits
@@ -91,6 +94,19 @@ MODULE_PARM_DESC(report_undeciphered, "Report undeciphered 
multi-touch state fie
 #define TRACKPAD_RES_Y \
((TRACKPAD_MAX_Y - TRACKPAD_MIN_Y) / (TRACKPAD_DIMENSION_Y / 100))
 
+#define TRACKPAD2_DIMENSION_X (float)16000
+#define TRACKPAD2_MIN_X -3678
+#define TRACKPAD2_MAX_X 3934
+#define TRACKPAD2_RES_X \
+   ((TRACKPAD2_MAX_X - TRACKPAD2_MIN_X) / (TRACKPAD2_DIMENSION_X / 100))
+#define TRACKPAD2_DIMENSION_Y (float)11490
+#define TRACKPAD2_MIN_Y -2478
+#define TRACKPAD2_MAX_Y 2587
+#define TRACKPAD2_RES_Y \
+   ((TRACKPAD2_MAX_Y - TRACKPAD2_MIN_Y) / (TRACKPAD2_DIMENSION_Y / 100))
+
+#define MAX_TOUCHES16
+
 /**
  * struct magicmouse_sc - Tracks Magic Mouse-specific data.
  * @input: Input device through which we report events.
@@ -115,8 +131,8 @@ struct magicmouse_sc {
short scroll_x;
short scroll_y;
u8 size;
-   } touches[16];
-   int tracking_ids[16];
+   } touches[MAX_TOUCHES];
+   int tracking_ids[MAX_TOUCHES];
 };
 
 static int magicmouse_firm_touch(struct magicmouse_sc *msc)
@@ -183,6 +199,7 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
 {
struct input_dev *input = msc->input;
int id, x, y, size, orientation, touch_major, touch_minor, state, down;
+   int pressure = 0;
 
if (input->id.product == USB_DEVICE_ID_APPLE_MAGICMOUSE) {
id = (tdata[6] << 2 | tdata[5] >> 6) & 0xf;
@@ -194,7 +211,7 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
touch_minor = tdata[4];
state = tdata[7] & TOUCH_STATE_MASK;
down = state != TOUCH_STATE_NONE;
-   } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD */
+   } else if (input->id.product == USB_DEVICE_ID_APPLE_MAGICTRACKPAD) {
id = (tdata[7] << 2 | tdata[6] >> 6) & 0xf;
x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19);
@@ -204,6 +221,17 @@ static void magicmouse_emit_touch(struct magicmouse_sc 
*msc, int raw_id, u8 *tda
touch_minor = tdata[5];
state = tdata[8] & TOUCH_STATE_MASK;
down = state != TOUCH_STATE_NONE;
+   } else { /* USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 */
+   id = tdata[8] & 0xf;
+   x = (tdata[1] << 27 | tdata[0] << 19) >> 19;
+   y = -((tdata[3] << 30 | tdata[2] << 22 | tdata[1] << 14) >> 19);
+   size = tdata[6];
+   orientation = (tdata[8] >> 5) - 4;
+   touch_major = tdata[4];
+   touch_minor = tdata[5];
+   pressure = tdata[7];
+   state = tdata[3] & 0xC0;
+   down = state == 0x80;
}
 
/* Store tracking ID and other fields.

[PATCH] [v2] HID: add support for Apple Magic Keyboards

2018-08-27 Thread Sean O'Brien
USB device
Vendor 05ac (Apple)
Device 026c (Magic Keyboard with Numeric Keypad)

Bluetooth devices
Vendor 004c (Apple)
Device 0267 (Magic Keyboard)
Device 026c (Magic Keyboard with Numeric Keypad)

Support already exists for the Magic Keyboard over USB connection.
Add support for the Magic Keyboard over Bluetooth connection, and for
the Magic Keyboard with Numeric Keypad over Bluetooth and USB
connection.

Signed-off-by: Sean O'Brien 
---

 drivers/hid/hid-apple.c | 9 -
 drivers/hid/hid-ids.h   | 2 ++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index 25b7bd56ae11..1cb41992aaa1 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -335,7 +335,8 @@ static int apple_input_mapping(struct hid_device *hdev, 
struct hid_input *hi,
struct hid_field *field, struct hid_usage *usage,
unsigned long **bit, int *max)
 {
-   if (usage->hid == (HID_UP_CUSTOM | 0x0003)) {
+   if (usage->hid == (HID_UP_CUSTOM | 0x0003) ||
+   usage->hid == (HID_UP_MSVENDOR | 0x0003)) {
/* The fn key on Apple USB keyboards */
set_bit(EV_REP, hi->input->evbit);
hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_FN);
@@ -472,6 +473,12 @@ static const struct hid_device_id apple_devices[] = {
.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI),
.driver_data = APPLE_HAS_FN },
+   { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI),
+   .driver_data = APPLE_HAS_FN },
+   { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI),
+   .driver_data = APPLE_HAS_FN },
+   { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI),
+   .driver_data = APPLE_HAS_FN },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_WELLSPRING_ANSI),
.driver_data = APPLE_HAS_FN },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_WELLSPRING_ISO),
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 79bdf0c7e351..5dbe3fb82690 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -88,6 +88,7 @@
 #define USB_DEVICE_ID_ANTON_TOUCH_PAD  0x3101
 
 #define USB_VENDOR_ID_APPLE0x05ac
+#define BT_VENDOR_ID_APPLE 0x004c
 #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE0x0304
 #define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d
 #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD  0x030e
@@ -157,6 +158,7 @@
 #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO   0x0256
 #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS   0x0257
 #define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI   0x0267
+#define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI   0x026c
 #define USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI   0x0290
 #define USB_DEVICE_ID_APPLE_WELLSPRING8_ISO0x0291
 #define USB_DEVICE_ID_APPLE_WELLSPRING8_JIS0x0292
-- 
2.19.0.rc0.228.g281dcd1b4d0-goog



[PATCH] [v2] HID: add support for Apple Magic Keyboards

2018-08-27 Thread Sean O'Brien
USB device
Vendor 05ac (Apple)
Device 026c (Magic Keyboard with Numeric Keypad)

Bluetooth devices
Vendor 004c (Apple)
Device 0267 (Magic Keyboard)
Device 026c (Magic Keyboard with Numeric Keypad)

Support already exists for the Magic Keyboard over USB connection.
Add support for the Magic Keyboard over Bluetooth connection, and for
the Magic Keyboard with Numeric Keypad over Bluetooth and USB
connection.

Signed-off-by: Sean O'Brien 
---

 drivers/hid/hid-apple.c | 9 -
 drivers/hid/hid-ids.h   | 2 ++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index 25b7bd56ae11..1cb41992aaa1 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -335,7 +335,8 @@ static int apple_input_mapping(struct hid_device *hdev, 
struct hid_input *hi,
struct hid_field *field, struct hid_usage *usage,
unsigned long **bit, int *max)
 {
-   if (usage->hid == (HID_UP_CUSTOM | 0x0003)) {
+   if (usage->hid == (HID_UP_CUSTOM | 0x0003) ||
+   usage->hid == (HID_UP_MSVENDOR | 0x0003)) {
/* The fn key on Apple USB keyboards */
set_bit(EV_REP, hi->input->evbit);
hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_FN);
@@ -472,6 +473,12 @@ static const struct hid_device_id apple_devices[] = {
.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI),
.driver_data = APPLE_HAS_FN },
+   { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI),
+   .driver_data = APPLE_HAS_FN },
+   { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI),
+   .driver_data = APPLE_HAS_FN },
+   { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI),
+   .driver_data = APPLE_HAS_FN },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_WELLSPRING_ANSI),
.driver_data = APPLE_HAS_FN },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_WELLSPRING_ISO),
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 79bdf0c7e351..5dbe3fb82690 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -88,6 +88,7 @@
 #define USB_DEVICE_ID_ANTON_TOUCH_PAD  0x3101
 
 #define USB_VENDOR_ID_APPLE0x05ac
+#define BT_VENDOR_ID_APPLE 0x004c
 #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE0x0304
 #define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d
 #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD  0x030e
@@ -157,6 +158,7 @@
 #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO   0x0256
 #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS   0x0257
 #define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI   0x0267
+#define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI   0x026c
 #define USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI   0x0290
 #define USB_DEVICE_ID_APPLE_WELLSPRING8_ISO0x0291
 #define USB_DEVICE_ID_APPLE_WELLSPRING8_JIS0x0292
-- 
2.19.0.rc0.228.g281dcd1b4d0-goog



Re: [PATCH] HID: add support for Apple Magic Keyboards

2018-08-27 Thread Sean O'Brien
On Mon, Aug 27, 2018 at 5:19 AM Benjamin Tissoires
 wrote:
>
> Hi Sean,
>
> On Thu, Aug 23, 2018 at 6:40 PM Sean O'Brien  wrote:
> >
> > USB device
> > Vendor 05ac (Apple)
> > Device 026c (Magic Keyboard with Numeric Keypad)
> >
> > Bluetooth devices
> > Vendor 004c (Apple)
> > Device 0267 (Magic Keyboard)
> > Device 026c (Magic Keyboard with Numeric Keypad)
> >
> > Support already exists for the Magic Keyboard over USB connection.
> > This patch adds support for the Magic Keyboard over Bluetooth
> > connection, and for the Magic Keyboard with Numeric Keypad over
> > Bluetooth and USB connection.
> >
> > Signed-off-by: Sean O'Brien 
> > ---
> >
> >  drivers/hid/hid-apple.c  | 9 -
> >  drivers/hid/hid-ids.h| 2 ++
> >  drivers/hid/hid-quirks.c | 3 +++
> >  3 files changed, 13 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
> > index 25b7bd56ae11..1cb41992aaa1 100644
> > --- a/drivers/hid/hid-apple.c
> > +++ b/drivers/hid/hid-apple.c
> > @@ -335,7 +335,8 @@ static int apple_input_mapping(struct hid_device *hdev, 
> > struct hid_input *hi,
> > struct hid_field *field, struct hid_usage *usage,
> > unsigned long **bit, int *max)
> >  {
> > -   if (usage->hid == (HID_UP_CUSTOM | 0x0003)) {
> > +   if (usage->hid == (HID_UP_CUSTOM | 0x0003) ||
> > +   usage->hid == (HID_UP_MSVENDOR | 0x0003)) {
> > /* The fn key on Apple USB keyboards */
> > set_bit(EV_REP, hi->input->evbit);
> > hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_FN);
> > @@ -472,6 +473,12 @@ static const struct hid_device_id apple_devices[] = {
> > .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
> > { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
> > USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI),
> > .driver_data = APPLE_HAS_FN },
> > +   { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, 
> > USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI),
> > +   .driver_data = APPLE_HAS_FN },
> > +   { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
> > USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI),
> > +   .driver_data = APPLE_HAS_FN },
> > +   { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, 
> > USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI),
> > +   .driver_data = APPLE_HAS_FN },
> > { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
> > USB_DEVICE_ID_APPLE_WELLSPRING_ANSI),
> > .driver_data = APPLE_HAS_FN },
> > { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
> > USB_DEVICE_ID_APPLE_WELLSPRING_ISO),
> > diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
> > index 79bdf0c7e351..5dbe3fb82690 100644
> > --- a/drivers/hid/hid-ids.h
> > +++ b/drivers/hid/hid-ids.h
> > @@ -88,6 +88,7 @@
> >  #define USB_DEVICE_ID_ANTON_TOUCH_PAD  0x3101
> >
> >  #define USB_VENDOR_ID_APPLE0x05ac
> > +#define BT_VENDOR_ID_APPLE 0x004c
> >  #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE0x0304
> >  #define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d
> >  #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD  0x030e
> > @@ -157,6 +158,7 @@
> >  #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO   0x0256
> >  #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS   0x0257
> >  #define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI   0x0267
> > +#define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI   0x026c
> >  #define USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI   0x0290
> >  #define USB_DEVICE_ID_APPLE_WELLSPRING8_ISO0x0291
> >  #define USB_DEVICE_ID_APPLE_WELLSPRING8_JIS0x0292
> > diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c
> > index 249d49b6b16c..a3b3aecf8628 100644
> > --- a/drivers/hid/hid-quirks.c
> > +++ b/drivers/hid/hid-quirks.c
> > @@ -270,6 +270,9 @@ static const struct hid_device_id 
> > hid_have_special_driver[] = {
> > { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 
> > USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO) },
> > { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 
> > USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS) },
> > { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
> > USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI) },
> > +   { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, 
> > USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI) },
> > +   { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
> >

Re: [PATCH] HID: add support for Apple Magic Keyboards

2018-08-27 Thread Sean O'Brien
On Mon, Aug 27, 2018 at 5:19 AM Benjamin Tissoires
 wrote:
>
> Hi Sean,
>
> On Thu, Aug 23, 2018 at 6:40 PM Sean O'Brien  wrote:
> >
> > USB device
> > Vendor 05ac (Apple)
> > Device 026c (Magic Keyboard with Numeric Keypad)
> >
> > Bluetooth devices
> > Vendor 004c (Apple)
> > Device 0267 (Magic Keyboard)
> > Device 026c (Magic Keyboard with Numeric Keypad)
> >
> > Support already exists for the Magic Keyboard over USB connection.
> > This patch adds support for the Magic Keyboard over Bluetooth
> > connection, and for the Magic Keyboard with Numeric Keypad over
> > Bluetooth and USB connection.
> >
> > Signed-off-by: Sean O'Brien 
> > ---
> >
> >  drivers/hid/hid-apple.c  | 9 -
> >  drivers/hid/hid-ids.h| 2 ++
> >  drivers/hid/hid-quirks.c | 3 +++
> >  3 files changed, 13 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
> > index 25b7bd56ae11..1cb41992aaa1 100644
> > --- a/drivers/hid/hid-apple.c
> > +++ b/drivers/hid/hid-apple.c
> > @@ -335,7 +335,8 @@ static int apple_input_mapping(struct hid_device *hdev, 
> > struct hid_input *hi,
> > struct hid_field *field, struct hid_usage *usage,
> > unsigned long **bit, int *max)
> >  {
> > -   if (usage->hid == (HID_UP_CUSTOM | 0x0003)) {
> > +   if (usage->hid == (HID_UP_CUSTOM | 0x0003) ||
> > +   usage->hid == (HID_UP_MSVENDOR | 0x0003)) {
> > /* The fn key on Apple USB keyboards */
> > set_bit(EV_REP, hi->input->evbit);
> > hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_FN);
> > @@ -472,6 +473,12 @@ static const struct hid_device_id apple_devices[] = {
> > .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
> > { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
> > USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI),
> > .driver_data = APPLE_HAS_FN },
> > +   { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, 
> > USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI),
> > +   .driver_data = APPLE_HAS_FN },
> > +   { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
> > USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI),
> > +   .driver_data = APPLE_HAS_FN },
> > +   { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, 
> > USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI),
> > +   .driver_data = APPLE_HAS_FN },
> > { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
> > USB_DEVICE_ID_APPLE_WELLSPRING_ANSI),
> > .driver_data = APPLE_HAS_FN },
> > { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
> > USB_DEVICE_ID_APPLE_WELLSPRING_ISO),
> > diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
> > index 79bdf0c7e351..5dbe3fb82690 100644
> > --- a/drivers/hid/hid-ids.h
> > +++ b/drivers/hid/hid-ids.h
> > @@ -88,6 +88,7 @@
> >  #define USB_DEVICE_ID_ANTON_TOUCH_PAD  0x3101
> >
> >  #define USB_VENDOR_ID_APPLE0x05ac
> > +#define BT_VENDOR_ID_APPLE 0x004c
> >  #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE0x0304
> >  #define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d
> >  #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD  0x030e
> > @@ -157,6 +158,7 @@
> >  #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO   0x0256
> >  #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS   0x0257
> >  #define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI   0x0267
> > +#define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI   0x026c
> >  #define USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI   0x0290
> >  #define USB_DEVICE_ID_APPLE_WELLSPRING8_ISO0x0291
> >  #define USB_DEVICE_ID_APPLE_WELLSPRING8_JIS0x0292
> > diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c
> > index 249d49b6b16c..a3b3aecf8628 100644
> > --- a/drivers/hid/hid-quirks.c
> > +++ b/drivers/hid/hid-quirks.c
> > @@ -270,6 +270,9 @@ static const struct hid_device_id 
> > hid_have_special_driver[] = {
> > { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 
> > USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO) },
> > { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 
> > USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS) },
> > { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
> > USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI) },
> > +   { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, 
> > USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI) },
> > +   { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
> >

[PATCH] HID: add support for Apple Magic Keyboards

2018-08-23 Thread Sean O'Brien
USB device
Vendor 05ac (Apple)
Device 026c (Magic Keyboard with Numeric Keypad)

Bluetooth devices
Vendor 004c (Apple)
Device 0267 (Magic Keyboard)
Device 026c (Magic Keyboard with Numeric Keypad)

Support already exists for the Magic Keyboard over USB connection.
This patch adds support for the Magic Keyboard over Bluetooth
connection, and for the Magic Keyboard with Numeric Keypad over
Bluetooth and USB connection.

Signed-off-by: Sean O'Brien 
---

 drivers/hid/hid-apple.c  | 9 -
 drivers/hid/hid-ids.h| 2 ++
 drivers/hid/hid-quirks.c | 3 +++
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index 25b7bd56ae11..1cb41992aaa1 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -335,7 +335,8 @@ static int apple_input_mapping(struct hid_device *hdev, 
struct hid_input *hi,
struct hid_field *field, struct hid_usage *usage,
unsigned long **bit, int *max)
 {
-   if (usage->hid == (HID_UP_CUSTOM | 0x0003)) {
+   if (usage->hid == (HID_UP_CUSTOM | 0x0003) ||
+   usage->hid == (HID_UP_MSVENDOR | 0x0003)) {
/* The fn key on Apple USB keyboards */
set_bit(EV_REP, hi->input->evbit);
hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_FN);
@@ -472,6 +473,12 @@ static const struct hid_device_id apple_devices[] = {
.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI),
.driver_data = APPLE_HAS_FN },
+   { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI),
+   .driver_data = APPLE_HAS_FN },
+   { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI),
+   .driver_data = APPLE_HAS_FN },
+   { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI),
+   .driver_data = APPLE_HAS_FN },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_WELLSPRING_ANSI),
.driver_data = APPLE_HAS_FN },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_WELLSPRING_ISO),
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 79bdf0c7e351..5dbe3fb82690 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -88,6 +88,7 @@
 #define USB_DEVICE_ID_ANTON_TOUCH_PAD  0x3101
 
 #define USB_VENDOR_ID_APPLE0x05ac
+#define BT_VENDOR_ID_APPLE 0x004c
 #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE0x0304
 #define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d
 #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD  0x030e
@@ -157,6 +158,7 @@
 #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO   0x0256
 #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS   0x0257
 #define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI   0x0267
+#define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI   0x026c
 #define USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI   0x0290
 #define USB_DEVICE_ID_APPLE_WELLSPRING8_ISO0x0291
 #define USB_DEVICE_ID_APPLE_WELLSPRING8_JIS0x0292
diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c
index 249d49b6b16c..a3b3aecf8628 100644
--- a/drivers/hid/hid-quirks.c
+++ b/drivers/hid/hid-quirks.c
@@ -270,6 +270,9 @@ static const struct hid_device_id hid_have_special_driver[] 
= {
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO) },
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS) },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI) },
+   { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI) },
+   { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI) },
+   { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI) },
{ 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
-- 
2.18.0.1017.ga543ac7ca45-goog



[PATCH] HID: add support for Apple Magic Keyboards

2018-08-23 Thread Sean O'Brien
USB device
Vendor 05ac (Apple)
Device 026c (Magic Keyboard with Numeric Keypad)

Bluetooth devices
Vendor 004c (Apple)
Device 0267 (Magic Keyboard)
Device 026c (Magic Keyboard with Numeric Keypad)

Support already exists for the Magic Keyboard over USB connection.
This patch adds support for the Magic Keyboard over Bluetooth
connection, and for the Magic Keyboard with Numeric Keypad over
Bluetooth and USB connection.

Signed-off-by: Sean O'Brien 
---

 drivers/hid/hid-apple.c  | 9 -
 drivers/hid/hid-ids.h| 2 ++
 drivers/hid/hid-quirks.c | 3 +++
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index 25b7bd56ae11..1cb41992aaa1 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -335,7 +335,8 @@ static int apple_input_mapping(struct hid_device *hdev, 
struct hid_input *hi,
struct hid_field *field, struct hid_usage *usage,
unsigned long **bit, int *max)
 {
-   if (usage->hid == (HID_UP_CUSTOM | 0x0003)) {
+   if (usage->hid == (HID_UP_CUSTOM | 0x0003) ||
+   usage->hid == (HID_UP_MSVENDOR | 0x0003)) {
/* The fn key on Apple USB keyboards */
set_bit(EV_REP, hi->input->evbit);
hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_FN);
@@ -472,6 +473,12 @@ static const struct hid_device_id apple_devices[] = {
.driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI),
.driver_data = APPLE_HAS_FN },
+   { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI),
+   .driver_data = APPLE_HAS_FN },
+   { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI),
+   .driver_data = APPLE_HAS_FN },
+   { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI),
+   .driver_data = APPLE_HAS_FN },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_WELLSPRING_ANSI),
.driver_data = APPLE_HAS_FN },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_WELLSPRING_ISO),
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 79bdf0c7e351..5dbe3fb82690 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -88,6 +88,7 @@
 #define USB_DEVICE_ID_ANTON_TOUCH_PAD  0x3101
 
 #define USB_VENDOR_ID_APPLE0x05ac
+#define BT_VENDOR_ID_APPLE 0x004c
 #define USB_DEVICE_ID_APPLE_MIGHTYMOUSE0x0304
 #define USB_DEVICE_ID_APPLE_MAGICMOUSE 0x030d
 #define USB_DEVICE_ID_APPLE_MAGICTRACKPAD  0x030e
@@ -157,6 +158,7 @@
 #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO   0x0256
 #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS   0x0257
 #define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI   0x0267
+#define USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI   0x026c
 #define USB_DEVICE_ID_APPLE_WELLSPRING8_ANSI   0x0290
 #define USB_DEVICE_ID_APPLE_WELLSPRING8_ISO0x0291
 #define USB_DEVICE_ID_APPLE_WELLSPRING8_JIS0x0292
diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c
index 249d49b6b16c..a3b3aecf8628 100644
--- a/drivers/hid/hid-quirks.c
+++ b/drivers/hid/hid-quirks.c
@@ -270,6 +270,9 @@ static const struct hid_device_id hid_have_special_driver[] 
= {
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO) },
{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS) },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI) },
+   { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_ANSI) },
+   { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI) },
+   { HID_BLUETOOTH_DEVICE(BT_VENDOR_ID_APPLE, 
USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_ANSI) },
{ 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
-- 
2.18.0.1017.ga543ac7ca45-goog