From patchwork Wed Jun 24 00:30:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: simon@mungewell.org X-Patchwork-Id: 6664331 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id ABC77C05AC for ; Wed, 24 Jun 2015 00:30:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A14042043C for ; Wed, 24 Jun 2015 00:30:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 864FD206A3 for ; Wed, 24 Jun 2015 00:30:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933532AbbFXAao (ORCPT ); Tue, 23 Jun 2015 20:30:44 -0400 Received: from host171.canaca.com ([67.55.55.225]:52079 "EHLO host171.canaca.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932515AbbFXAaj (ORCPT ); Tue, 23 Jun 2015 20:30:39 -0400 Received: from [208.118.126.162] (helo=LinuxBuild.TOPCON.COM) by host171.canaca.com with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) (envelope-from ) id 1Z7YaM-0000su-FS; Tue, 23 Jun 2015 20:30:38 -0400 From: Simon Wood To: linux-input@vger.kernel.org Cc: Frank Praznik , linux-iio@vger.kernel.org, Simon Wood Subject: [RFC_v2 4/4] HID: hid-sony: Add IIO support for DualShock4 Controller Date: Tue, 23 Jun 2015 18:30:30 -0600 Message-Id: <1435105830-2297-5-git-send-email-simon@mungewell.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1435105830-2297-1-git-send-email-simon@mungewell.org> References: <1435105830-2297-1-git-send-email-simon@mungewell.org> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - host171.canaca.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - mungewell.org X-Source: X-Source-Args: X-Source-Dir: Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP --- drivers/hid/hid-sony.c | 87 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 79 insertions(+), 8 deletions(-) diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index ce0526d..f1c1a16 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -62,7 +62,7 @@ DUALSHOCK4_CONTROLLER) #define SONY_BATTERY_SUPPORT (SIXAXIS_CONTROLLER | DUALSHOCK4_CONTROLLER) #define SONY_FF_SUPPORT (SIXAXIS_CONTROLLER | DUALSHOCK4_CONTROLLER) -#define SONY_IIO_SUPPORT SIXAXIS_CONTROLLER +#define SONY_IIO_SUPPORT (SIXAXIS_CONTROLLER | DUALSHOCK4_CONTROLLER) #define MAX_LEDS 4 @@ -848,13 +848,16 @@ struct sony_sc { #if IS_BUILTIN(CONFIG_IIO) || \ (IS_MODULE(CONFIG_IIO) && IS_MODULE(CONFIG_HID_SONY)) struct iio_dev *indio_dev; - __u16 last_data[3]; + __s16 last_data[6]; }; enum sony_iio_axis { AXIS_ACC_X, AXIS_ACC_Y, AXIS_ACC_Z, + AXIS_GYRO_X, + AXIS_GYRO_Y, + AXIS_GYRO_Z, }; static void sony_iio_trigger_work(struct irq_work *work); @@ -863,7 +866,7 @@ struct sony_iio { struct sony_sc *sc; struct iio_trigger *trig; - u8 buff[16]; /* 3x 16-bit + padding + timestamp */ + u8 buff[24]; /* 6x 16-bit + padding + timestamp */ struct irq_work work; #endif }; @@ -1095,6 +1098,25 @@ static int sony_raw_event(struct hid_device *hdev, struct hid_report *report, } else if (((sc->quirks & DUALSHOCK4_CONTROLLER_USB) && rd[0] == 0x01 && size == 64) || ((sc->quirks & DUALSHOCK4_CONTROLLER_BT) && rd[0] == 0x11 && size == 78)) { +#if IS_BUILTIN(CONFIG_IIO) || \ + (IS_MODULE(CONFIG_IIO) && IS_MODULE(CONFIG_HID_SONY)) + int offset = (sc->quirks & DUALSHOCK4_CONTROLLER_USB) ? 13 : 15; + + sc->last_data[AXIS_ACC_X] = (rd[offset+7] << 8) + rd[offset+6]; + sc->last_data[AXIS_ACC_Y] = (rd[offset+9] << 8) + rd[offset+8]; + sc->last_data[AXIS_ACC_Z] = (rd[offset+11] << 8) + rd[offset+10]; + + sc->last_data[AXIS_GYRO_X] = (rd[offset+1] << 8) + rd[offset]; + sc->last_data[AXIS_GYRO_Y] = (rd[offset+3] << 8) + rd[offset+2]; + sc->last_data[AXIS_GYRO_Z] = (rd[offset+5] << 8) + rd[offset+4]; + + if (sc->indio_dev) { + struct sony_iio *data; + + data = iio_priv(sc->indio_dev); + sony_iio_trigger_work(&data->work); + } +#endif dualshock4_parse_report(sc, rd, size); } @@ -1827,6 +1849,7 @@ static int sony_iio_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_RAW: switch (chan->type) { case IIO_ACCEL: + case IIO_ANGL_VEL: *val = data->sc->last_data[chan->address]; return IIO_VAL_INT; default: @@ -1835,8 +1858,17 @@ static int sony_iio_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_SCALE: switch (chan->type) { case IIO_ACCEL: - *val = 0; /* 9.80665/117 = 0.084540086 */ - *val2 = 84540; + if (data->sc->quirks & SIXAXIS_CONTROLLER) { + *val = 0; /* 9.80665/117 = 0.084540086 */ + *val2 = 84540; + } else if (data->sc->quirks & DUALSHOCK4_CONTROLLER) { + *val = 0; /* 9.80665/8192 = 0.001197101 */ + *val2 = 1197; + } + return IIO_VAL_INT_PLUS_MICRO; + case IIO_ANGL_VEL: + *val = 0; /* 0.001 */ + *val2 = 1000; return IIO_VAL_INT_PLUS_MICRO; default: return -EINVAL; @@ -1844,7 +1876,13 @@ static int sony_iio_read_raw(struct iio_dev *indio_dev, case IIO_CHAN_INFO_OFFSET: switch (chan->type) { case IIO_ACCEL: - *val = -512; + if (data->sc->quirks & SIXAXIS_CONTROLLER) + *val = -512; + else if (data->sc->quirks & DUALSHOCK4_CONTROLLER) + *val = 0; + return IIO_VAL_INT; + case IIO_ANGL_VEL: + *val = 0; return IIO_VAL_INT; default: return -EINVAL; @@ -1871,6 +1909,23 @@ static int sony_iio_read_raw(struct iio_dev *indio_dev, }, \ } +#define SONY_GYRO_CHANNEL(_axis) { \ + .type = IIO_ANGL_VEL, \ + .modified = 1, \ + .channel2 = IIO_MOD_##_axis, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_OFFSET), \ + .address = AXIS_GYRO_##_axis, \ + .scan_index = AXIS_GYRO_##_axis, \ + .scan_type = { \ + .sign = 's', \ + .realbits = 16, \ + .storagebits = 16, \ + .shift = 0, \ + }, \ +} + static const struct iio_chan_spec sony_sixaxis_channels[] = { SONY_ACC_CHANNEL(X), SONY_ACC_CHANNEL(Y), @@ -1878,6 +1933,16 @@ static const struct iio_chan_spec sony_sixaxis_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(3), }; +static const struct iio_chan_spec sony_dualshock4_channels[] = { + SONY_ACC_CHANNEL(X), + SONY_ACC_CHANNEL(Y), + SONY_ACC_CHANNEL(Z), + SONY_GYRO_CHANNEL(X), + SONY_GYRO_CHANNEL(Y), + SONY_GYRO_CHANNEL(Z), + IIO_CHAN_SOFT_TIMESTAMP(6), +}; + static const struct iio_info sony_iio_info = { .read_raw = &sony_iio_read_raw, .driver_module = THIS_MODULE, @@ -1943,8 +2008,14 @@ static int sony_iio_probe(struct sony_sc *sc) indio_dev->name = dev_name(&hdev->dev); indio_dev->modes = INDIO_DIRECT_MODE | INDIO_BUFFER_TRIGGERED; indio_dev->info = &sony_iio_info; - indio_dev->channels = sony_sixaxis_channels; - indio_dev->num_channels = ARRAY_SIZE(sony_sixaxis_channels); + + if (sc->quirks & SIXAXIS_CONTROLLER) { + indio_dev->channels = sony_sixaxis_channels; + indio_dev->num_channels = ARRAY_SIZE(sony_sixaxis_channels); + } else if (sc->quirks & DUALSHOCK4_CONTROLLER) { + indio_dev->channels = sony_dualshock4_channels; + indio_dev->num_channels = ARRAY_SIZE(sony_dualshock4_channels); + } data->trig = iio_trigger_alloc("%s-dev%d", indio_dev->name, indio_dev->id);