From nobody Sun Aug 20 09:54:52 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RT9vK38DHz4r1Bn; Sun, 20 Aug 2023 09:54:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RT9vK1NKmz3QWS; Sun, 20 Aug 2023 09:54:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692525293; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BbwwNTTmY83QP5sHySG3J2X3C2W88XzbjX5T1ntjFDE=; b=hyDkEN6DBD/mDMprwSZKDypdwzuG6e7/xHLjDPCdkRr3vzU6OIcGH2v5TZ/afWHAidHAJK xc7gya00/cCQ0Ts17IOlMgYsQtMfXnrikahNr7AV/7QAI4ifYokT2yF2mjh1lt1YIFoFAU CTosrPoh4D/0G0h/9aJVmZucp9+cN488kQ1hndGBrfA+WK5DuqAkNQrS44bh9w1AiRaKLO 4eDYIOsqcH5sUBOnoB47vQmZqwsMT2wvbEOktNxl/Vn3FG2J4Cu4ltNjCaVwY4k6Q1jCvd K0T6H5n0wpVS/AU5mi+v6coFxrUHlZasmX9UDrWqwEpF8UGTZy4d/h3Z1rYohA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692525293; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BbwwNTTmY83QP5sHySG3J2X3C2W88XzbjX5T1ntjFDE=; b=iSa9CV3prZLNsh+vYCtj7V/CR0HFhmX4bk4v3orECgY+xa4wD/noPXj3B3TfXjYfkZB44L NWqDJYSmJJGQ+Aww9dA99r06AEdTtd+DF/tt5NEhW0d160nRaTNdqaJ6wPtRH+eNaXb7x0 xRb1wIgC/FdkV9p1lkicwb838wTa0qifMjj28Txt8OhSVVu4wmyGw+lv5kHA2CcSfaP7dA bZiohz020jQIUDEdzN52o5NmyKnjBGAdnPtooNbsaP3kWoJnitNSTX5Ywk5Pm99IJPsahA I/uDcAv2pccqR9nGlo5uLxz2RHrQ22BiJUB2L7bgLpEuYAmKe9l1gaBe9QxzWw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1692525293; a=rsa-sha256; cv=none; b=EdSLQHB9BjMFtOtzH7COQu4Sjx1r1LJ5LSLE462AznbLCT7UMP0xmNmSRiBzBDrihiI4ad +LLOSxdJNs+274Nx1tJ+xuAVjecg/LXNHeoeUpPPnZS6oqlZpBxpEYvAMfIJ7tddToidPx bies7LeqQU7OlXF1A3kB6EEErVPyqpyb4GqIgwAeuhkPe4/9i8VeqYRqMOD8esvRU+DwKP T3HskV11cujvTobwFCQMYNnV3TLWpoVUlZij1Auk2d69bhfPJwM8dd6arxo0pnmDkDltbb Ud+c0vlfKsrVnnSay/1FY6NzSV+FfuoEDW8OOG5edB8hyZTtbNySPhwVb8Cupg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RT9vK096bzb3n; Sun, 20 Aug 2023 09:54:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 37K9sq9D081521; Sun, 20 Aug 2023 09:54:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37K9sqT1081518; Sun, 20 Aug 2023 09:54:52 GMT (envelope-from git) Date: Sun, 20 Aug 2023 09:54:52 GMT Message-Id: <202308200954.37K9sqT1081518@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vladimir Kondratyev Subject: git: 1c4edee342bb - main - bcm5974(4): add support for devices attached over SPI bus List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wulf X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 1c4edee342bba99aff29da38b164a862492f1d78 Auto-Submitted: auto-generated The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=1c4edee342bba99aff29da38b164a862492f1d78 commit 1c4edee342bba99aff29da38b164a862492f1d78 Author: Val Packett AuthorDate: 2023-08-20 09:53:32 +0000 Commit: Vladimir Kondratyev CommitDate: 2023-08-20 09:53:32 +0000 bcm5974(4): add support for devices attached over SPI bus Reviewed by: wulf --- sys/dev/hid/bcm5974.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 92 insertions(+), 7 deletions(-) diff --git a/sys/dev/hid/bcm5974.c b/sys/dev/hid/bcm5974.c index 1d99c7edd5b1..c803412ecb76 100644 --- a/sys/dev/hid/bcm5974.c +++ b/sys/dev/hid/bcm5974.c @@ -52,7 +52,7 @@ #include "usbdevs.h" -#define BCM5974_BUFFER_MAX (248 * 4) /* 4 Type4 SPI frames */ +#define BCM5974_BUFFER_MAX (246 * 2) /* 2 Type4 SPI frames */ #define BCM5974_TLC_PAGE HUP_GENERIC_DESKTOP #define BCM5974_TLC_USAGE HUG_MOUSE @@ -208,7 +208,11 @@ enum { BCM5974_FLAG_WELLSPRING7, BCM5974_FLAG_WELLSPRING7A, BCM5974_FLAG_WELLSPRING8, - BCM5974_FLAG_WELLSPRING9, + BCM5974_FLAG_WELLSPRING9_MODEL3, + BCM5974_FLAG_WELLSPRING9_MODEL4, +#define BCM5974_FLAG_WELLSPRING9_MODEL_SPI BCM5974_FLAG_WELLSPRING9_MODEL4 + BCM5974_FLAG_WELLSPRING9_MODEL5, + BCM5974_FLAG_WELLSPRING9_MODEL6, BCM5974_FLAG_MAGIC_TRACKPAD2_USB, BCM5974_FLAG_MAX, }; @@ -352,7 +356,7 @@ static const struct bcm5974_dev_params bcm5974_dev_params[BCM5974_FLAG_MAX] = { * No scientific measurements have been done :) but a really hard press * results in a value around 3500 on model 4. */ - [BCM5974_FLAG_WELLSPRING9] = { + [BCM5974_FLAG_WELLSPRING9_MODEL3] = { .tp = tp + TYPE4, .p = { SN_PRESSURE, 0, 4096, 4096 }, .w = { SN_WIDTH, 0, 2048, 0 }, @@ -361,6 +365,33 @@ static const struct bcm5974_dev_params bcm5974_dev_params[BCM5974_FLAG_MAX] = { .o = { SN_ORIENT, -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 }, }, + [BCM5974_FLAG_WELLSPRING9_MODEL4] = { + .tp = tp + TYPE4, + .p = { SN_PRESSURE, 0, 4096, 4096 }, + .w = { SN_WIDTH, 0, 2048, 0 }, + .x = { SN_COORD, -5087, 5579, 105 }, + .y = { SN_COORD, -182, 6089, 75 }, + .o = { SN_ORIENT, + -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 }, + }, + [BCM5974_FLAG_WELLSPRING9_MODEL5] = { + .tp = tp + TYPE4, + .p = { SN_PRESSURE, 0, 4096, 4096 }, + .w = { SN_WIDTH, 0, 2048, 0 }, + .x = { SN_COORD, -6243, 6749, 105 }, + .y = { SN_COORD, -170, 7685, 75 }, + .o = { SN_ORIENT, + -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 }, + }, + [BCM5974_FLAG_WELLSPRING9_MODEL6] = { + .tp = tp + TYPE4, + .p = { SN_PRESSURE, 0, 4096, 4096 }, + .w = { SN_WIDTH, 0, 2048, 0 }, + .x = { SN_COORD, -7456, 7976, 105 }, + .y = { SN_COORD, -163, 9283, 75 }, + .o = { SN_ORIENT, + -MAX_FINGER_ORIENTATION, MAX_FINGER_ORIENTATION, 0 }, + }, [BCM5974_FLAG_MAGIC_TRACKPAD2_USB] = { .tp = tp + TYPE_MT2U, .p = { SN_PRESSURE, 0, 256, 256 }, @@ -376,6 +407,12 @@ static const struct bcm5974_dev_params bcm5974_dev_params[BCM5974_FLAG_MAX] = { HID_TLC(BCM5974_TLC_PAGE, BCM5974_TLC_USAGE), \ } +#define APPLE_HID "APP000D" +#define BCM5974_DEV_SPI(hid, i) { \ + HID_BUS(BUS_SPI), HID_PNP(hid), HID_DRIVER_INFO(i), \ + HID_TLC(BCM5974_TLC_PAGE, BCM5974_TLC_USAGE), \ +} + static const struct hid_device_id bcm5974_devs[] = { /* MacbookAir1.1 */ BCM5974_DEV(APPLE, WELLSPRING_ANSI, BCM5974_FLAG_WELLSPRING1), @@ -439,14 +476,20 @@ static const struct hid_device_id bcm5974_devs[] = { BCM5974_DEV(APPLE, WELLSPRING8_JIS, BCM5974_FLAG_WELLSPRING8), /* MacbookPro12,1 MacbookPro11,4 */ - BCM5974_DEV(APPLE, WELLSPRING9_ANSI, BCM5974_FLAG_WELLSPRING9), - BCM5974_DEV(APPLE, WELLSPRING9_ISO, BCM5974_FLAG_WELLSPRING9), - BCM5974_DEV(APPLE, WELLSPRING9_JIS, BCM5974_FLAG_WELLSPRING9), + BCM5974_DEV(APPLE, WELLSPRING9_ANSI, BCM5974_FLAG_WELLSPRING9_MODEL3), + BCM5974_DEV(APPLE, WELLSPRING9_ISO, BCM5974_FLAG_WELLSPRING9_MODEL3), + BCM5974_DEV(APPLE, WELLSPRING9_JIS, BCM5974_FLAG_WELLSPRING9_MODEL3), + + /* Generic SPI device */ + BCM5974_DEV_SPI(APPLE_HID, BCM5974_FLAG_WELLSPRING9_MODEL_SPI), /* External "Magic" devices */ BCM5974_DEV(APPLE, MAGIC_TRACKPAD2, BCM5974_FLAG_MAGIC_TRACKPAD2_USB), }; +#define BCM5974_WELLSPRING9_RDESC_SIZE 110 +#define BCM5974_WELLSPRING9_MODEL_OFFSET 106 + struct bcm5974_softc { device_t sc_dev; struct evdev_dev *sc_evdev; @@ -593,6 +636,44 @@ bcm5974_set_device_mode(struct bcm5974_softc *sc, bool on) return (err); } +static uintptr_t +bcm5974_get_wsp9_model(device_t dev) +{ + const struct hid_device_info *hw = hid_get_device_info(dev); + static uint8_t rdesc[BCM5974_WELLSPRING9_RDESC_SIZE]; + uint8_t model_byte = 0; + + bus_topo_assert(); + + if (hw->rdescsize == sizeof(rdesc) && + hid_get_rdesc(dev, rdesc, sizeof(rdesc)) == 0) { + model_byte = rdesc[BCM5974_WELLSPRING9_MODEL_OFFSET]; + switch (model_byte) { + case 3: + /* MacbookPro12,1 MacbookPro11,4 */ + return (BCM5974_FLAG_WELLSPRING9_MODEL3); + case 4: + /* Macbook8,1 Macbook9,1 Macbook10,1 */ + return (BCM5974_FLAG_WELLSPRING9_MODEL4); + case 5: + /* + * MacbookPro13,1 MacbookPro13,2 + * MacbookPro14,1 MacbookPro14,2 + */ + return (BCM5974_FLAG_WELLSPRING9_MODEL5); + case 6: + /* MacbookPro13,3 MacbookPro14,3 */ + return (BCM5974_FLAG_WELLSPRING9_MODEL6); + } + } + + device_printf(dev, "Unexpected trackpad descriptor len=%u model_byte=" + "%u, not extracting model\n", hw->rdescsize, model_byte); + + /* Fallback for unknown SPI versions */ + return (BCM5974_FLAG_WELLSPRING9_MODEL_SPI); +} + static void bcm5974_identify(driver_t *driver, device_t parent) { @@ -631,6 +712,7 @@ bcm5974_attach(device_t dev) { struct bcm5974_softc *sc = device_get_softc(dev); const struct hid_device_info *hw = hid_get_device_info(dev); + uintptr_t drv_info; int err; DPRINTFN(BCM5974_LLEVEL_INFO, "sc=%p\n", sc); @@ -638,7 +720,10 @@ bcm5974_attach(device_t dev) sc->sc_dev = dev; /* get device specific configuration */ - sc->sc_params = bcm5974_dev_params + hidbus_get_driver_info(dev); + drv_info = hidbus_get_driver_info(dev); + if (drv_info == BCM5974_FLAG_WELLSPRING9_MODEL_SPI) + drv_info = bcm5974_get_wsp9_model(dev); + sc->sc_params = bcm5974_dev_params + drv_info; sc->sc_evdev = evdev_alloc(); evdev_set_name(sc->sc_evdev, device_get_desc(dev));