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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions drivers/hid/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ 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_HAPTIC
tristate "Apple MTP Haptic Actuator support"
depends on HID
help
Say Y here if you want support for allowing a "Host controlled" touchpad mode
where userspace has control of manually triggering haptic click and deep-click
effects on the apple haptic trackpad. This is independent of the autonomous
clicking that triggers without userspace input by default.


config HID_APPLEIR
tristate "Apple infrared receiver"
depends on (USB_HID)
Expand Down Expand Up @@ -739,6 +749,7 @@ config LOGIWHEELS_FF

config HID_MAGICMOUSE
tristate "Apple Magic Mouse/Trackpad multi-touch support"
depends on (HID && HID_APPLE_HAPTIC) || HID_APPLE_HAPTIC=n
help
Support for the Apple Magic Mouse/Trackpad multi-touch.

Expand Down
1 change: 1 addition & 0 deletions drivers/hid/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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_HAPTIC) += hid-apple-haptic.o
obj-$(CONFIG_HID_APPLEIR) += hid-appleir.o
obj-$(CONFIG_HID_APPLETB_BL) += hid-appletb-bl.o
obj-$(CONFIG_HID_APPLETB_KBD) += hid-appletb-kbd.o
Expand Down
8 changes: 1 addition & 7 deletions drivers/hid/dockchannel-hid/dockchannel-hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,12 +593,6 @@ static int dchid_get_report_cmd(struct dchid_iface *iface, u8 reportnum, void *b
return ret <= 0 ? ret : ret - 1;
}

/* Note: buf includes report number! */
static int dchid_set_report(struct dchid_iface *iface, void *buf, size_t len)
{
return dchid_cmd(iface, HID_OUTPUT_REPORT, REQ_SET_REPORT, buf, len, NULL, 0);
}

static int dchid_raw_request(struct hid_device *hdev,
unsigned char reportnum, __u8 *buf, size_t len,
unsigned char rtype, int reqtype)
Expand All @@ -610,7 +604,7 @@ static int dchid_raw_request(struct hid_device *hdev,
buf[0] = reportnum;
return dchid_cmd(iface, rtype, REQ_GET_REPORT, &reportnum, 1, buf + 1, len - 1);
case HID_REQ_SET_REPORT:
return dchid_set_report(iface, buf, len);
return dchid_cmd(iface, rtype, REQ_SET_REPORT, buf, len, NULL, 0);
default:
return -EIO;
}
Expand Down
118 changes: 118 additions & 0 deletions drivers/hid/hid-apple-haptic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// SPDX-License-Identifier: GPL-2.0-or-later

#include "asm-generic/errno-base.h"
#include "hid-ids.h"
#include "linux/gfp_types.h"
#include "linux/hid.h"
#include <linux/soc/apple/actuator.h>

int apple_taptic_send(struct hid_device *haptic_hdev, u16 effect_type, u8 strength, u8 softness)
{
int ret;
u8 *msg;
int msg_length;
u8 event_click[] = {0x53, 0x01, strength, softness, 0x03, 0x02, 0x22, 0x48, 0x49,
0x01, 0x04, 0x60, 0x17, 0x2D, 0x03, 0x02, 0x18, 0x32, 0x1E};
u8 event_deep_click[] = {0x53, 0x01, strength, softness, 0x01, 0x07, 0x18, 0x18, 0x4F,
0x02, 0x02, 0x60, 0x0C, 0x25};
u8 event_release[] = {0x53, 0x01, strength, softness};

switch (effect_type) {
case HID_HP_WAVEFORMPRESS & HID_USAGE:
msg = event_click;
msg_length = sizeof(event_click);
break;
case APPLE_HP_WAVEFORMDEEPCLICK & HID_USAGE:
msg = event_deep_click;
msg_length = sizeof(event_deep_click);
break;
case HID_HP_WAVEFORMRELEASE & HID_USAGE:
msg = event_release;
msg_length = sizeof(event_release);
break;
default:
return -EINVAL;
}

msg = kmemdup(msg, msg_length, GFP_KERNEL);
if (!msg)
return -ENOMEM;

ret = hid_hw_raw_request(haptic_hdev, msg[0], msg, msg_length,
HID_OUTPUT_REPORT, HID_REQ_SET_REPORT);
kfree(msg);

if (ret < 0)
return ret;
return 0;
}
EXPORT_SYMBOL_GPL(apple_taptic_send);

int apple_taptic_switch_modes(struct hid_device *haptic_hdev, bool enable_host_controlled)
{
int ret;
u8 *buf;
u8 msg[] = { 0x21, enable_host_controlled };

buf = kmemdup(msg, sizeof(msg), GFP_KERNEL);
if (!buf)
return -ENOMEM;

ret = hid_hw_raw_request(haptic_hdev, buf[0], buf, sizeof(msg),
HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
kfree(buf);

if (ret < 0)
return ret;
return 0;
}
EXPORT_SYMBOL_GPL(apple_taptic_switch_modes);

static int apple_actuator_probe(struct hid_device *haptic_hdev, const struct hid_device_id *id)
{
int ret;

ret = hid_parse(haptic_hdev);
if (ret) {
hid_err(haptic_hdev, "apple_haptic hid parse failed\n");
return ret;
}

ret = hid_hw_start(haptic_hdev, 0);
if (ret) {
hid_err(haptic_hdev, "apple_haptic hw start failed\n");
return ret;
}

return 0;
}

static bool actuator_match(struct hid_device *hdev, bool ignore_special_drivers)
{
return (strcmp(hdev->name, "Apple MTP actuator") == 0);
}

static void actuator_remove(struct hid_device *haptic_hdev)
{
apple_taptic_switch_modes(haptic_hdev, 0);
hid_hw_stop(haptic_hdev);
}

static const struct hid_device_id apple_haptic_devices[] = {
{ HID_DEVICE(BUS_HOST, HID_GROUP_ANY, HOST_VENDOR_ID_APPLE,
HID_ANY_ID), .driver_data = 0 },
{ }
};
MODULE_DEVICE_TABLE(hid, apple_haptic_devices);

static struct hid_driver apple_actuator_driver = {
.name = "apple-trackpad-haptics",
.id_table = apple_haptic_devices,
.probe = apple_actuator_probe,
.match = actuator_match,
.remove = actuator_remove
};
module_hid_driver(apple_actuator_driver);

MODULE_DESCRIPTION("Apple MTP Haptic Actuator driver");
MODULE_LICENSE("GPL");
Loading