From patchwork Mon Mar 18 20:39:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H. Nikolaus Schaller" X-Patchwork-Id: 10858551 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B4F131575 for ; Mon, 18 Mar 2019 20:40:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9AD1428671 for ; Mon, 18 Mar 2019 20:40:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8EBCF2947C; Mon, 18 Mar 2019 20:40:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86E6728671 for ; Mon, 18 Mar 2019 20:40:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727208AbfCRUjm (ORCPT ); Mon, 18 Mar 2019 16:39:42 -0400 Received: from mo4-p01-ob.smtp.rzone.de ([85.215.255.54]:25813 "EHLO mo4-p01-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727269AbfCRUjl (ORCPT ); Mon, 18 Mar 2019 16:39:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1552941575; s=strato-dkim-0002; d=goldelico.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=c4tuE4gteQoT1p3n8nW5XW4/vRQj2bFZ1ppqRtio/NY=; b=AB5z4ki5T3GoIZ3j4c18CHDHv8AEdY0uV+aKq979rM2uYyR8lJFScqhf1daEg9eo4I J7VZ4LkdXhSPXP1OcrPSuAG9UAqHE7EwiqMbnpjU5ByjvphYkk6ksy5gMuN50z+FCLvX M0sPIPeiFL3j6EUcHHi5CH1u5FdftZiaLQ4z2oZmSCp8t434rkfwr27gYUbMyyH9j0H6 tFfmfCNdU+YuDHo1iZQMymvcWTyEj/NwLhGN6wrqelXnb+/XwQSuPF0Cp5HfJRs9WtZh gGqT1XFZdgnak2+P0sZhGTEEhJi93rzpzYXs5cl/k6njm/LgXPSWYfV9nbUGW1XpMes0 h2Yg== X-RZG-AUTH: ":JGIXVUS7cutRB/49FwqZ7WcJeFKiMhflhwDubTJ9o1OAA2UNf2M7O2CKNdGj" X-RZG-CLASS-ID: mo00 Received: from iMac.fritz.box by smtp.strato.de (RZmta 44.16 DYNA|AUTH) with ESMTPSA id h04075v2IKdYFyj (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Mon, 18 Mar 2019 21:39:34 +0100 (CET) From: "H. Nikolaus Schaller" To: Jonathan Cameron Cc: letux-kernel@openphoenux.org, kernel@pyra-handheld.com, Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, "H. Nikolaus Schaller" Subject: [RFC 1/4] iio: input-bridge: optionally bridge iio acceleometers to create a /dev/input Date: Mon, 18 Mar 2019 21:39:31 +0100 Message-Id: <88389d5de8925a0c6ee31bbe8d1ce0ea4b6a6035.1552941573.git.hns@goldelico.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some user spaces (e.g. some Android devices) use /dev/input/event* for handling the 3D position of the device with respect to the center of gravity (earth). This can be used for gaming input, auto-rotation of screens etc. This interface should be the standard because it is an abstraction of how orientation data is acquired from sensor chips. Sensor chips may be connected through different interfaces and in different positions. They may also have different parameters. And, if a chip is replaced by a different one, the values reported by the device position interface should remain the same, provided the device tree reflects the changed chip. But nowadays, new accelerometer chips mostly get iio drivers and rarely input drivers. Therefore we need something like a protocol stack: input device vs. raw data. It can be seen as a similar layering like TCP/IP vs. bare Ethernet. Or keyboard input events vs. raw gpio or raw USB access. This patch bridges the gap between raw iio data and the input device abstraction so that accelerometer measurements can also be presented as X/Y/Z accelerometer channels (INPUT_PROP_ACCELEROMETER) through /dev/input/event*. There are no special requirements or changes needed for an iio driver. This driver simply collects the first 3 accelerometer channels as X, Y and Z. If only 1 or 2 channels are available, they are used for X and Y only. Additional channels are ignored. Scaling is done automatically so that 1g is represented by value 256 and range is assumed to be -511 .. +511. If a mount-matrix is provided by the iio driver, it is also taken into account so that the input event automatically gets the correct orientation with respect to the device. If this extension is not configured into the kernel it takes no resources (except source code). If it is configured, but there is no accelerometer, there is only a tiny penalty for scanning for accelerometer channels once during probe of each iio device. If it runs, the driver polls the device(s) once every 100 ms. A mode where the iio device defines the update rate is not implemented and for further study. The driver is capable of supporting up to 5 iio accelerometers and they are presented by unique /dev/input/event* files. The iio chip name is used to define the input device name so that it can be identified (e.g. by udev rules or evtest). Signed-off-by: H. Nikolaus Schaller --- drivers/iio/industrialio-inputbridge.c | 420 +++++++++++++++++++++++++ drivers/iio/industrialio-inputbridge.h | 28 ++ 2 files changed, 448 insertions(+) create mode 100644 drivers/iio/industrialio-inputbridge.c create mode 100644 drivers/iio/industrialio-inputbridge.h diff --git a/drivers/iio/industrialio-inputbridge.c b/drivers/iio/industrialio-inputbridge.c new file mode 100644 index 000000000000..0288ba2ef69f --- /dev/null +++ b/drivers/iio/industrialio-inputbridge.c @@ -0,0 +1,420 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * The Industrial I/O core, bridge to input devices + * + * Copyright (c) 2016-2019 Golden Delicious Computers GmbH&Co. KG + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include + +#include "industrialio-inputbridge.h" + +/* currently, only polling is implemented */ +#define POLLING_MSEC 100 + +/* handle up to this number of input devices */ +#define MAX_INPUT_DEVICES 5 + +#define FIXED_POINT_UNIT 1000 + +static struct iio_input_map { + struct iio_dev *indio_dev; /* the iio device */ + struct input_dev *input; /* the input device */ + struct iio_channel channels[3]; /* x, y, z channels */ + int values[3]; /* values while processing */ + struct matrix { + int mxx, myx, mzx; /* translated and scaled mount-matrix */ + int mxy, myy, mzy; + int mxz, myz, mzz; + } matrix; +} devices[MAX_INPUT_DEVICES]; + +static inline struct iio_input_map *to_iio_input_map( + struct iio_channel *channel) +{ + return (struct iio_input_map *) channel->data; +} + +/* we must protect against races in channel allocation */ + +static DEFINE_MUTEX(inputbridge_device_mutex); + +static struct delayed_work input_work; + +/* we can start/stop the worker by open("/dev/input/event") */ +static int open_count; + +/* we must protect the open counter */ +static DEFINE_MUTEX(inputbridge_open_mutex); + +/* minimum and maximum range we want to report */ +#define ABSMAX_ACC_VAL (512 - 1) +#define ABSMIN_ACC_VAL -(ABSMAX_ACC_VAL) + +/* scale processed iio values so that 1g maps to ABSMAX_ACC_VAL / 2 */ +#define SCALE ((100 * ABSMAX_ACC_VAL) / (2 * 981)) + +/* + * convert float string to scaled fixed point format, e.g. + * 1.23 -> 1230 + * 0.1234 -> 123 + * .01234 -> 12 + */ + +static int32_t atofix(const char *str) +{ + int32_t mant = 0; + bool sign = false; + bool decimal = false; + int32_t divisor = 1; + + if (*str == '-') + sign = true, str++; + while (*str && divisor < FIXED_POINT_UNIT) { + if (*str >= '0' && *str <= '9') { + mant = 10 * mant + (*str - '0'); + if (decimal) + divisor *= 10; + } else if (*str == '.') + decimal = true; + else + return 0; /* error */ + str++; + } + + mant = (FIXED_POINT_UNIT * mant) / divisor; + if (sign) + mant = -mant; + + return mant; +} + +static void iio_apply_matrix(struct matrix *m, int *in, int *out) +{ + /* apply mount matrix */ + out[0] = (m->mxx * in[0] + m->myx * in[1] + m->mzx * in[2]) + / FIXED_POINT_UNIT; + out[1] = (m->mxy * in[0] + m->myy * in[1] + m->mzy * in[2]) + / FIXED_POINT_UNIT; + out[2] = (m->mxz * in[0] + m->myz * in[1] + m->mzz * in[2]) + / FIXED_POINT_UNIT; +} + +static void iio_accel_report_channels(void) +{ + int dindex; + + for (dindex = 0; dindex < ARRAY_SIZE(devices); dindex++) { + struct iio_input_map *map = &devices[dindex]; + + /* device might become closed while we are still processing */ + mutex_lock(&inputbridge_device_mutex); + + if (map->input) { + int aligned_values[3]; + int cindex = 0; + + while (cindex < ARRAY_SIZE(map->channels)) { + struct iio_channel *channel = + &map->channels[cindex]; + int val; + int ret; + + if (!channel->indio_dev) + continue; + + ret = iio_read_channel_raw(channel, &val); + + if (ret < 0) { + pr_err("%s(): channel read error %d\n", + __func__, cindex); + return; + } + + ret = iio_convert_raw_to_processed(channel, val, + &map->values[cindex], SCALE); + + if (ret < 0) { + pr_err("%s(): channel processing error\n", + __func__); + return; + } + + cindex++; + } + + iio_apply_matrix(&map->matrix, map->values, + aligned_values); + + input_report_abs(map->input, ABS_X, aligned_values[0]); + input_report_abs(map->input, ABS_Y, aligned_values[1]); + input_report_abs(map->input, ABS_Z, aligned_values[2]); + input_sync(map->input); + } + + mutex_unlock(&inputbridge_device_mutex); + } +} + +static void iio_inputbridge_work(struct work_struct *work) +{ + struct delayed_work *delayed_work; + + delayed_work = to_delayed_work(work); + + mutex_lock(&inputbridge_open_mutex); + + iio_accel_report_channels(); + + schedule_delayed_work(delayed_work, + msecs_to_jiffies(POLLING_MSEC)); + + mutex_unlock(&inputbridge_open_mutex); +} + +static int iio_accel_open(struct input_dev *input) +{ + struct iio_dev *iiodev = input_get_drvdata(input); + + mutex_lock(&inputbridge_open_mutex); + + /* start on first open */ + if (open_count++ == 0) + schedule_delayed_work(&input_work, + msecs_to_jiffies(0)); + + mutex_unlock(&inputbridge_open_mutex); + + return 0; +} + +static void iio_accel_close(struct input_dev *input) +{ + struct iio_dev *iiodev = input_get_drvdata(input); + + mutex_lock(&inputbridge_open_mutex); + + /* stop after last close */ + if (--open_count == 0) + cancel_delayed_work(&input_work); + + mutex_unlock(&inputbridge_open_mutex); +} + +static int iio_input_register_accel_channel(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan) +{ /* we found some accelerometer channel */ + int ret; + + int dindex, cindex; + struct iio_input_map *map; + + mutex_lock(&inputbridge_device_mutex); + + /* look for existing input device for this iio device */ + + for (dindex = 0; dindex < ARRAY_SIZE(devices); dindex++) { + if (devices[dindex].indio_dev == indio_dev) + break; + } + + if (dindex == ARRAY_SIZE(devices)) { + struct input_dev *input; + const struct iio_chan_spec_ext_info *ext_info; + + /* not found, look for a free slot for a new input device */ + + for (dindex = 0; dindex < ARRAY_SIZE(devices); dindex++) { + if (!devices[dindex].input) + break; + } + + if (dindex == ARRAY_SIZE(devices)) { + mutex_unlock(&inputbridge_device_mutex); + return -ENOMEM; + } + + input = input_allocate_device(); + + if (!input) { + mutex_unlock(&inputbridge_device_mutex); + return -ENOMEM; + } + + input->name = kasprintf(GFP_KERNEL, "iio-bridge: %s", + indio_dev->name); + input->phys = kasprintf(GFP_KERNEL, "accel/input%d", + dindex); + +// input->id.bustype = BUS_I2C; +// input->dev.parent = &indio_dev->client->dev; + + set_bit(INPUT_PROP_ACCELEROMETER, input->propbit); + + input->evbit[0] = BIT_MASK(EV_ABS); + input->open = iio_accel_open; + input->close = iio_accel_close; + +// FIXME: what happens if we unregister the first device? +// and then register another one? + + if (dindex == 0) // first input + INIT_DELAYED_WORK(&input_work, iio_inputbridge_work); + + input_set_drvdata(input, indio_dev); + + input_alloc_absinfo(input); + ret = input_register_device(input); + + if (ret < 0) { + kfree(input->name); + kfree(input->phys); + input_free_device(input); + mutex_unlock(&inputbridge_device_mutex); + return ret; + } + + map = &devices[dindex]; + + map->input = input; + map->indio_dev = indio_dev; + + /* assume all channels of a device share the same matrix */ + + ext_info = chan->ext_info; + for (; ext_info && ext_info->name; ext_info++) { + if (strcmp(ext_info->name, "mount_matrix") == 0) + break; + } + + if (ext_info && ext_info->name) { + /* matrix found */ + uintptr_t priv = ext_info->private; + const struct iio_mount_matrix *mtx; + + mtx = ((iio_get_mount_matrix_t *) priv)(indio_dev, + chan); + + map->matrix.mxx = atofix(mtx->rotation[0]); + map->matrix.myx = atofix(mtx->rotation[1]); + map->matrix.mzx = atofix(mtx->rotation[2]); + map->matrix.mxy = atofix(mtx->rotation[3]); + map->matrix.myy = atofix(mtx->rotation[4]); + map->matrix.mzy = atofix(mtx->rotation[5]); + map->matrix.mxz = atofix(mtx->rotation[6]); + map->matrix.myz = atofix(mtx->rotation[7]); + map->matrix.mzz = atofix(mtx->rotation[8]); + } else { + map->matrix.mxx = FIXED_POINT_UNIT; + map->matrix.myx = 0; + map->matrix.mzx = 0; + map->matrix.mxy = 0; + map->matrix.myy = FIXED_POINT_UNIT; + map->matrix.mzy = 0; + map->matrix.mxz = 0; + map->matrix.myz = 0; + map->matrix.mzz = FIXED_POINT_UNIT; + } + } + + /* find free channel within this device block */ + map = &devices[dindex]; + + for (cindex = 0; cindex < ARRAY_SIZE(map->channels); cindex++) { + if (!map->channels[cindex].indio_dev) + break; + } + + /* check if we already have collected enough channels */ + if (cindex == ARRAY_SIZE(map->channels)) { + mutex_unlock(&inputbridge_device_mutex); + return 0; /* silently ignore */ + } + + map->channels[cindex].indio_dev = indio_dev; + map->channels[cindex].channel = chan; + map->channels[cindex].data = (void *) &devices[dindex]; + + switch (cindex) { + case 0: + input_set_abs_params(map->input, ABS_X, ABSMIN_ACC_VAL, + ABSMAX_ACC_VAL, 0, 0); + break; + case 1: + input_set_abs_params(map->input, ABS_Y, ABSMIN_ACC_VAL, + ABSMAX_ACC_VAL, 0, 0); + break; + case 2: + input_set_abs_params(map->input, ABS_Z, ABSMIN_ACC_VAL, + ABSMAX_ACC_VAL, 0, 0); + break; + } + mutex_unlock(&inputbridge_device_mutex); + + return 0; +} + +int iio_device_register_inputbridge(struct iio_dev *indio_dev) +{ + int i; + + for (i = 0; i < indio_dev->num_channels; i++) { + const struct iio_chan_spec *chan = + &indio_dev->channels[i]; + + if (chan->type == IIO_ACCEL) { + int r = iio_input_register_accel_channel(indio_dev, + chan); + + if (r < 0) + return r; + } + } + + return 0; +} + +void iio_device_unregister_inputbridge(struct iio_dev *indio_dev) +{ + struct input_dev *input = NULL; + + int dindex = 0; + + mutex_lock(&inputbridge_device_mutex); + + for (; dindex < ARRAY_SIZE(devices); dindex++) { + int cindex = 0; + + while (cindex < ARRAY_SIZE(devices[dindex].channels)) { + struct iio_channel *channel = + &devices[dindex].channels[cindex]; + + /* mark slot as empty */ + if (channel->indio_dev == indio_dev) + channel->indio_dev = NULL; + cindex++; + } + input_unregister_device(input); + kfree(input->name); + kfree(input->phys); + input_free_device(input); + + devices[dindex].indio_dev = NULL; + devices[dindex].input = NULL; + } + + mutex_unlock(&inputbridge_device_mutex); +} + +MODULE_AUTHOR("H. Nikolaus Schaller "); +MODULE_DESCRIPTION("Bridge to present Industrial I/O accelerometers as properly oriented Input devices"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/industrialio-inputbridge.h b/drivers/iio/industrialio-inputbridge.h new file mode 100644 index 000000000000..1363b10ab3f7 --- /dev/null +++ b/drivers/iio/industrialio-inputbridge.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * The Industrial I/O core, bridge to input devices + * + * Copyright (c) 2016-2019 Golden Delicious Computers GmbH&Co. KG + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + */ + +#if defined(CONFIG_IIO_INPUT_BRIDGE) + +extern int iio_device_register_inputbridge(struct iio_dev *indio_dev); +extern void iio_device_unregister_inputbridge(struct iio_dev *indio_dev); + +#else + +static inline int iio_device_register_inputbridge(struct iio_dev *indio_dev) +{ + return 0; +} + +static inline void iio_device_unregister_inputbridge(struct iio_dev *indio_dev) +{ +} + +#endif From patchwork Mon Mar 18 20:39:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H. Nikolaus Schaller" X-Patchwork-Id: 10858547 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BEF19139A for ; Mon, 18 Mar 2019 20:40:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6F632948C for ; Mon, 18 Mar 2019 20:40:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8FA6628751; Mon, 18 Mar 2019 20:40:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A5C829464 for ; Mon, 18 Mar 2019 20:40:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727779AbfCRUjo (ORCPT ); Mon, 18 Mar 2019 16:39:44 -0400 Received: from mo4-p02-ob.smtp.rzone.de ([81.169.146.171]:17153 "EHLO mo4-p02-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727718AbfCRUjo (ORCPT ); Mon, 18 Mar 2019 16:39:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1552941582; s=strato-dkim-0002; d=goldelico.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=QPIeEIgDRSxNIo4wn8msfWv7mzRHbhu6YqbA8itgAH0=; b=Xp+OXJ6IGQYPN0kX/RfLUGbT6hGw5hX4+rtHKQXFOqeia9A82tPowPzrnUiOrO2A+p CNKOFVv78cDmW+yF0Fo2ByOJtSFU6MZIAsB3IZsIG0w7gfiwsXvdW7BF6TsESgpo2oKT 8ZVzy88mBsoKd4GF+XEaUvXYdupJ6eJpzWBB2Ct88dx+vEHyKj5CuFYPfiqMxN9WLJq2 ODZBih6JewzYF53FB+RTldOoXyadaRcSqjL5kdgUAybWFTXqiqy+xg/nN7+2Yamz6RP1 +QOSWVJr4ILvM78XB0BCSIpA3u+OLkxvfAiOP4DrQlixC1PTp1shL8YkSwIJB6GDrD7s 6vFw== X-RZG-AUTH: ":JGIXVUS7cutRB/49FwqZ7WcJeFKiMhflhwDubTJ9o1OAA2UNf2M7O2CKNdGj" X-RZG-CLASS-ID: mo00 Received: from iMac.fritz.box by smtp.strato.de (RZmta 44.16 DYNA|AUTH) with ESMTPSA id h04075v2IKdZFyk (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Mon, 18 Mar 2019 21:39:35 +0100 (CET) From: "H. Nikolaus Schaller" To: Jonathan Cameron Cc: letux-kernel@openphoenux.org, kernel@pyra-handheld.com, Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, "H. Nikolaus Schaller" Subject: [RFC 2/4] iio: input-bridge: add iio-input-bridge to Makefile Date: Mon, 18 Mar 2019 21:39:32 +0100 Message-Id: X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add the iio-input-bridge to the Makefile. Signed-off-by: H. Nikolaus Schaller --- drivers/iio/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile index cb5993251381..d695e5a27da5 100644 --- a/drivers/iio/Makefile +++ b/drivers/iio/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_IIO) += industrialio.o industrialio-y := industrialio-core.o industrialio-event.o inkern.o industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o +industrialio-$(CONFIG_IIO_INPUT_BRIDGE) += industrialio-inputbridge.o obj-$(CONFIG_IIO_CONFIGFS) += industrialio-configfs.o obj-$(CONFIG_IIO_SW_DEVICE) += industrialio-sw-device.o From patchwork Mon Mar 18 20:39:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H. Nikolaus Schaller" X-Patchwork-Id: 10858549 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BBE27139A for ; Mon, 18 Mar 2019 20:40:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4C6C28614 for ; Mon, 18 Mar 2019 20:40:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A32AB28751; Mon, 18 Mar 2019 20:40:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4346628769 for ; Mon, 18 Mar 2019 20:40:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727766AbfCRUjo (ORCPT ); Mon, 18 Mar 2019 16:39:44 -0400 Received: from mo4-p02-ob.smtp.rzone.de ([85.215.255.83]:31288 "EHLO mo4-p02-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727717AbfCRUjo (ORCPT ); Mon, 18 Mar 2019 16:39:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1552941582; s=strato-dkim-0002; d=goldelico.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=FpLcXXgjhB0Nq7Ef4DEJHTwPb2IbK1p9ddEH3G+5TaQ=; b=dOIYfjg/yEcLQIFe/ngIvXgSR/hJdvHy9JoXjV4sP3hwkxtSeTF+9Ey36eL0hBqd3l x9V0cF8ibUrdn0DlrbE1uAUuysjyvLmA+S4Jq/yHnEMOG47DFuX+y/btbSAyqsldP9TV G8pTEeLHBVoF5WOISyhwkBEUxaPpBgmmYJRRX0hHhDgKJSl/YpqS/Fcm3UdfsUetZlVo ST+8dY75ZaOPARjQu+YF/j3CfxaBxeXvBNnqeZRmKOqqBj17LxVmAYFfjWY0vT1d7c0E CmVgkSxIOL4ls7YJBpgu930lXN7KM+YW8656wCWLaIviJQg9RKg3IAWYsjLerUh8wo5Z VLiw== X-RZG-AUTH: ":JGIXVUS7cutRB/49FwqZ7WcJeFKiMhflhwDubTJ9o1OAA2UNf2M7O2CKNdGj" X-RZG-CLASS-ID: mo00 Received: from iMac.fritz.box by smtp.strato.de (RZmta 44.16 DYNA|AUTH) with ESMTPSA id h04075v2IKdZFyl (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Mon, 18 Mar 2019 21:39:35 +0100 (CET) From: "H. Nikolaus Schaller" To: Jonathan Cameron Cc: letux-kernel@openphoenux.org, kernel@pyra-handheld.com, Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, "H. Nikolaus Schaller" Subject: [RFC 3/4] iio: input-bridge: add IIO_INPUT_BRIDGE kernel config option Date: Mon, 18 Mar 2019 21:39:33 +0100 Message-Id: <290e3d7ff2a55281cd29bc48ac75cce0bd4e9af0.1552941573.git.hns@goldelico.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add the iio-input-bridge to the Kconfig. Signed-off-by: H. Nikolaus Schaller --- drivers/iio/Kconfig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig index d08aeb41cd07..d85afe002613 100644 --- a/drivers/iio/Kconfig +++ b/drivers/iio/Kconfig @@ -68,6 +68,13 @@ config IIO_TRIGGERED_EVENT help Provides helper functions for setting up triggered events. +config IIO_INPUT_BRIDGE + bool "Enable accelerometer bridge to input driver" + help + Provides a /dev/input/event* device for accelerometers + to use as a 3D input device, e.g. for gaming or auto-rotation + of screen contents. + source "drivers/iio/accel/Kconfig" source "drivers/iio/adc/Kconfig" source "drivers/iio/afe/Kconfig" From patchwork Mon Mar 18 20:39:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H. Nikolaus Schaller" X-Patchwork-Id: 10858545 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4A7CA1575 for ; Mon, 18 Mar 2019 20:40:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3359C28769 for ; Mon, 18 Mar 2019 20:40:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 276BA2945E; Mon, 18 Mar 2019 20:40:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1771E29486 for ; Mon, 18 Mar 2019 20:40:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727799AbfCRUkB (ORCPT ); Mon, 18 Mar 2019 16:40:01 -0400 Received: from mo4-p02-ob.smtp.rzone.de ([81.169.146.170]:28375 "EHLO mo4-p02-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727269AbfCRUjp (ORCPT ); Mon, 18 Mar 2019 16:39:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1552941583; s=strato-dkim-0002; d=goldelico.com; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=PZ2Eo8d+YhwTy/BkqIPSZ4MMMCqG6vW1xSs6GtuCSkk=; b=Gi8/vuU6n3tAyPUtZgmwCP+KIESdyNN0NjHpeS/vn8fD+BPI/bfsrKXuf7T7IioOxb rTYmF40G8nPbsq6Iiyubzt/p95Ahzt3cQIfxViKVLz1mSRcNsVr43a5y7T6L5mrXJbx2 bFShR7qF+o7YSMQf1H/Eg+a52cSOZMZkOR8dluVthU/G9VvP+Qxh7fzb+qQGvH8j48c2 k6stOdCphG8pZHnFtgOsJqSXvtqPCWi3I2dhDAswLDTA7+WHcIiJ2v/TIthvoSJQPPse wmcbZCUekbtv0s2Wwz90M8WaGvmbCTXbJvHPUo1SiqujPyFo+XNN4itSCmkXd2aJAywp +1eg== X-RZG-AUTH: ":JGIXVUS7cutRB/49FwqZ7WcJeFKiMhflhwDubTJ9o1OAA2UNf2M7O2CKNdGj" X-RZG-CLASS-ID: mo00 Received: from iMac.fritz.box by smtp.strato.de (RZmta 44.16 DYNA|AUTH) with ESMTPSA id h04075v2IKdZFym (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Mon, 18 Mar 2019 21:39:35 +0100 (CET) From: "H. Nikolaus Schaller" To: Jonathan Cameron Cc: letux-kernel@openphoenux.org, kernel@pyra-handheld.com, Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, "H. Nikolaus Schaller" Subject: [RFC 4/4] iio: input-bridge: make the iio-input-bridge driver called by iio-core Date: Mon, 18 Mar 2019 21:39:34 +0100 Message-Id: X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This adds the iio-input-bridge to iio device (un)registering so that accelerometers are located and made present an input event device. Signed-off-by: H. Nikolaus Schaller --- drivers/iio/industrialio-core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 4700fd5d8c90..81f412b41a78 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -29,6 +29,7 @@ #include #include "iio_core.h" #include "iio_core_trigger.h" +#include "industrialio-inputbridge.h" #include #include #include @@ -1723,6 +1724,15 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod) if (ret < 0) goto error_unreg_eventset; + ret = iio_device_register_inputbridge(indio_dev); + if (ret) { + dev_err(indio_dev->dev.parent, + "Failed to register as input driver\n"); + device_del(&indio_dev->dev); + + return ret; + } + return 0; error_unreg_eventset: @@ -1745,6 +1755,8 @@ void iio_device_unregister(struct iio_dev *indio_dev) { mutex_lock(&indio_dev->info_exist_lock); + iio_device_unregister_inputbridge(indio_dev); + cdev_device_del(&indio_dev->chrdev, &indio_dev->dev); iio_device_unregister_debugfs(indio_dev);