Received: by 10.223.164.202 with SMTP id h10csp402990wrb; Wed, 8 Nov 2017 19:15:31 -0800 (PST) X-Google-Smtp-Source: ABhQp+SleSUMmmQ3xbjg7+YkgjT+lm2Z5Eg8v/TZrqHNZTK8aAoknsExsh0ySKVBn8hLxqzRsT3X X-Received: by 10.99.184.25 with SMTP id p25mr2430103pge.180.1510197331656; Wed, 08 Nov 2017 19:15:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510197331; cv=none; d=google.com; s=arc-20160816; b=AIiSPzQNBtu1LOgLcTKmbZN0a4fWbvSs4SotRtPAk7fvZLV1YpjwqviJL9h/FK5W0C ywihX0CjXuffUdkNGJYPPPdseLDmhzE3Vs2cqxzH5cbjFAXMmztJ4dnlxIdyu45f7kD1 vLdHuOmAG2n7WvgdhR/Pc9cOsIYR8v3IQomjVhvm2V/3muk5qJU1NBF1HF4hCw9sfKIB Ph+m7UFqFyeRYT7pRiqcawopNq2Va1tJJ8mTs0YgSO8AgiipSuGJTdHDnOHQ+D5OzxzI zMx/DWlCbo14Xdc5S4Ls+5tZdKwbwQgoJJ3Q1JVtvwEc3LuW9yzIf8MvtdEynH4SG1rV 9BUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=YgLcbUDIbITF9EYwZu2fX8jp9bFg2IKBvDRHs0O/slw=; b=MzC6IRzPCxgdvtJPRGgAUZRsNfMjqFinUV7NIWUyf2+wZK90GTsI8snBe/o1twQ4Ol BCLBBEKj0v4k6DNg7Is2WyO/3Z8FZ6SXXjApdW2KExpPJ22xMsibftocJcBeT0ei8EHG tu8+VgEGhEeM7SsfMmFYBYN4FgFIa5G3QEMuju/Ry4yDXJEC8tff+N2N9jtvngikmztZ OdeQnZMLI7asT1eZpcaRB9CWmK7JkO1sa+CrZSfDesjlD4EXTY7pktWprANpzIDiV70p U5CmH070nllgy2wCy7puNd9/S6wkF93Y0ZJ39Zy4jzXpB3W7VOw+gN/hppPyrhRl63S4 HSXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ArOts9Rb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m63si5126574pld.243.2017.11.08.19.15.20; Wed, 08 Nov 2017 19:15:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ArOts9Rb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752309AbdKIDND (ORCPT + 82 others); Wed, 8 Nov 2017 22:13:03 -0500 Received: from mail-io0-f193.google.com ([209.85.223.193]:52663 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751749AbdKIDNB (ORCPT ); Wed, 8 Nov 2017 22:13:01 -0500 Received: by mail-io0-f193.google.com with SMTP id f20so8248846ioj.9; Wed, 08 Nov 2017 19:13:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=YgLcbUDIbITF9EYwZu2fX8jp9bFg2IKBvDRHs0O/slw=; b=ArOts9RbumIhgMdRpKz/2JPvlh7phsT0UdVC/14BtxKOnmfBI9C4jsDX247SAlj2bG RKb/huyCs71Gn3J/yUFonFKZ9KCfA96HosSmhTX1nzGOeR0YKXi/CIriRiH68qVmsslK a0qayLzltM6fI6wKaqqASsMtHZsqUeMXPSDKFLTaUAbE+LxmVR/lhupN1RMWaNR2SWOJ O5VVhcqYw1KrXbjENgtm2IEQhewGIny/llMZmrS+4pjQDaeiMQ4arWWR24kK8LEdxi3V qDaN3IXkg5XqTFtcSaLDd6xKCp6u1HVJXFWq83wKrjbrZbRzI5klyCNuJ9NNDFgwPboo 9J7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=YgLcbUDIbITF9EYwZu2fX8jp9bFg2IKBvDRHs0O/slw=; b=CHsMzoto95WwvDuc0xMJ4ZdcRCB9Y/jGgbjQ6u5Qgu/huimnByybNA5LGGZAeDlsTQ A952lzv4b0hpYciLu+ryqzxLZ/ZjRzuUQYsc+FFqKLSv4WW99VqV3UCZUw3BgRUk2ywf RtDgwbylXsMVZLe+gvyqsEmTdIyWxFwZbtjJab0zA4ux+vpjRUgEMoaA/S1isQV6sEcv hNqdHDBv4/hMJRQBHw7YlOH8TnMBzUfjWjs/eNFY65/soV3aI5UoV9VAZYvrLfSlv64p A+l1jIwW9v4crFX8zvQ3vHN76+iCtZsHmX2TYT2Nr/GeXp0WToMtKoSb1pZInipfv2G3 yVoA== X-Gm-Message-State: AJaThX60B46AD7hU5vjOQj23oFV/rePzTQEs1WaN4DBmrU0hkd/Puxs6 UKvCo5ObXFrGJ9VQ+TIb8Ik= X-Received: by 10.107.6.140 with SMTP id f12mr3327108ioi.4.1510197180132; Wed, 08 Nov 2017 19:13:00 -0800 (PST) Received: from hary-Aspire-X3400G.Belkin ([97.70.80.173]) by smtp.googlemail.com with ESMTPSA id 80sm2671596ioz.54.2017.11.08.19.12.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 08 Nov 2017 19:12:59 -0800 (PST) From: Harinath Nampally To: jic23@kernel.org Cc: knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, amsfield22@gmail.com, martink@posteo.de Subject: [PATCH] iio: accel: mma8452: Add single pulse/tap event detection Date: Wed, 8 Nov 2017 22:12:57 -0500 Message-Id: <1510197177-9434-1-git-send-email-harinath922@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds following related changes: - defines pulse event related registers - enables and handles single pulse interrupt for fxls8471 - handles IIO_EV_DIR_EITHER in read/write callbacks (because event direction for pulse is either rising or falling) - configures read/write event value for pulse latency register using IIO_EV_INFO_HYSTERESIS - adds multiple events like pulse and tranient event spec as elements of event_spec array named 'mma8452_accel_events' Except mma8653 chip all other chips like mma845x and fxls8471 have single tap detection feature. Tested thoroughly using iio_event_monitor application on imx6ul-evk board which has fxls8471. Signed-off-by: Harinath Nampally --- drivers/iio/accel/mma8452.c | 156 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 151 insertions(+), 5 deletions(-) diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c index 43c3a6b..36f1b56 100644 --- a/drivers/iio/accel/mma8452.c +++ b/drivers/iio/accel/mma8452.c @@ -72,6 +72,19 @@ #define MMA8452_TRANSIENT_THS_MASK GENMASK(6, 0) #define MMA8452_TRANSIENT_COUNT 0x20 #define MMA8452_TRANSIENT_CHAN_SHIFT 1 +#define MMA8452_PULSE_CFG 0x21 +#define MMA8452_PULSE_CFG_CHAN(chan) BIT(chan * 2) +#define MMA8452_PULSE_CFG_ELE BIT(6) +#define MMA8452_PULSE_SRC 0x22 +#define MMA8452_PULSE_SRC_XPULSE BIT(4) +#define MMA8452_PULSE_SRC_YPULSE BIT(5) +#define MMA8452_PULSE_SRC_ZPULSE BIT(6) +#define MMA8452_PULSE_THS 0x23 +#define MMA8452_PULSE_THS_MASK GENMASK(6, 0) +#define MMA8452_PULSE_COUNT 0x26 +#define MMA8452_PULSE_CHAN_SHIFT 2 +#define MMA8452_PULSE_LTCY 0x27 + #define MMA8452_CTRL_REG1 0x2a #define MMA8452_CTRL_ACTIVE BIT(0) #define MMA8452_CTRL_DR_MASK GENMASK(5, 3) @@ -91,6 +104,7 @@ #define MMA8452_INT_DRDY BIT(0) #define MMA8452_INT_FF_MT BIT(2) +#define MMA8452_INT_PULSE BIT(3) #define MMA8452_INT_TRANS BIT(5) #define MMA8451_DEVICE_ID 0x1a @@ -155,6 +169,16 @@ static const struct mma8452_event_regs trans_ev_regs = { .ev_count = MMA8452_TRANSIENT_COUNT, }; +static const struct mma8452_event_regs pulse_ev_regs = { + .ev_cfg = MMA8452_PULSE_CFG, + .ev_cfg_ele = MMA8452_PULSE_CFG_ELE, + .ev_cfg_chan_shift = MMA8452_PULSE_CHAN_SHIFT, + .ev_src = MMA8452_PULSE_SRC, + .ev_ths = MMA8452_PULSE_THS, + .ev_ths_mask = MMA8452_PULSE_THS_MASK, + .ev_count = MMA8452_PULSE_COUNT, +}; + /** * struct mma_chip_info - chip specific data * @chip_id: WHO_AM_I register's value @@ -784,6 +808,14 @@ static int mma8452_get_event_regs(struct mma8452_data *data, case IIO_EV_DIR_FALLING: *ev_reg = &ff_mt_ev_regs; return 0; + case IIO_EV_DIR_EITHER: + if (!(data->chip_info->all_events + & MMA8452_INT_PULSE) || + !(data->chip_info->enabled_events + & MMA8452_INT_PULSE)) + return -EINVAL; + *ev_reg = &pulse_ev_regs; + return 0; default: return -EINVAL; } @@ -848,6 +880,25 @@ static int mma8452_read_event_value(struct iio_dev *indio_dev, return ret; } + case IIO_EV_INFO_HYSTERESIS: + if (!(data->chip_info->all_events & MMA8452_INT_PULSE) || + !(data->chip_info->enabled_events & MMA8452_INT_PULSE)) + return -EINVAL; + + ret = i2c_smbus_read_byte_data(data->client, + MMA8452_PULSE_LTCY); + if (ret < 0) + return ret; + + power_mode = mma8452_get_power_mode(data); + if (power_mode < 0) + return power_mode; + + us = ret * mma8452_time_step_us[power_mode][ + mma8452_get_odr_index(data)]; + *val = us / USEC_PER_SEC; + *val2 = us % USEC_PER_SEC; + return IIO_VAL_INT_PLUS_MICRO; default: @@ -908,6 +959,24 @@ static int mma8452_write_event_value(struct iio_dev *indio_dev, return mma8452_change_config(data, MMA8452_TRANSIENT_CFG, reg); + case IIO_EV_INFO_HYSTERESIS: + if (!(data->chip_info->all_events & MMA8452_INT_PULSE) || + !(data->chip_info->enabled_events & MMA8452_INT_PULSE)) + return -EINVAL; + + ret = mma8452_get_power_mode(data); + if (ret < 0) + return ret; + + steps = (val * USEC_PER_SEC + val2) / + mma8452_time_step_us[ret][ + mma8452_get_odr_index(data)]; + + if (steps < 0 || steps > 0xff) + return -EINVAL; + + return mma8452_change_config(data, MMA8452_PULSE_LTCY, steps); + default: return -EINVAL; } @@ -937,6 +1006,14 @@ static int mma8452_read_event_config(struct iio_dev *indio_dev, return !!(ret & BIT(chan->scan_index + ev_regs->ev_cfg_chan_shift)); + case IIO_EV_DIR_EITHER: + ret = i2c_smbus_read_byte_data(data->client, + ev_regs->ev_cfg); + if (ret < 0) + return ret; + + return !!(ret & BIT(chan->scan_index * + ev_regs->ev_cfg_chan_shift)); default: return -EINVAL; } @@ -988,6 +1065,25 @@ static int mma8452_write_event_config(struct iio_dev *indio_dev, val |= ev_regs->ev_cfg_ele; return mma8452_change_config(data, ev_regs->ev_cfg, val); + + case IIO_EV_DIR_EITHER: + val = i2c_smbus_read_byte_data(data->client, ev_regs->ev_cfg); + if (val < 0) + return val; + + if (state) { + val &= ~BIT(chan->scan_index * + ev_regs->ev_cfg_chan_shift); + val |= BIT(chan->scan_index * + ev_regs->ev_cfg_chan_shift); + } else { + val &= ~BIT(chan->scan_index * + ev_regs->ev_cfg_chan_shift); + } + + val |= ev_regs->ev_cfg_ele; + + return mma8452_change_config(data, ev_regs->ev_cfg, val); default: return -EINVAL; } @@ -1025,6 +1121,38 @@ static void mma8452_transient_interrupt(struct iio_dev *indio_dev) ts); } +static void mma8452_pulse_interrupt(struct iio_dev *indio_dev) +{ + struct mma8452_data *data = iio_priv(indio_dev); + s64 ts = iio_get_time_ns(indio_dev); + int src; + + src = i2c_smbus_read_byte_data(data->client, MMA8452_PULSE_SRC); + if (src < 0) + return; + + if (src & MMA8452_PULSE_SRC_XPULSE) + iio_push_event(indio_dev, + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, IIO_MOD_X, + IIO_EV_TYPE_MAG, + IIO_EV_DIR_EITHER), + ts); + + if (src & MMA8452_PULSE_SRC_YPULSE) + iio_push_event(indio_dev, + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, IIO_MOD_Y, + IIO_EV_TYPE_MAG, + IIO_EV_DIR_EITHER), + ts); + + if (src & MMA8452_PULSE_SRC_ZPULSE) + iio_push_event(indio_dev, + IIO_MOD_EVENT_CODE(IIO_ACCEL, 0, IIO_MOD_Z, + IIO_EV_TYPE_MAG, + IIO_EV_DIR_EITHER), + ts); +} + static irqreturn_t mma8452_interrupt(int irq, void *p) { struct iio_dev *indio_dev = p; @@ -1063,6 +1191,11 @@ static irqreturn_t mma8452_interrupt(int irq, void *p) ret = IRQ_HANDLED; } + if (src & MMA8452_INT_PULSE) { + mma8452_pulse_interrupt(indio_dev); + ret = IRQ_HANDLED; + } + return ret; } @@ -1130,8 +1263,10 @@ static const struct iio_event_spec mma8652_freefall_event[] = { }, }; -static const struct iio_event_spec mma8452_transient_event[] = { + +static const struct iio_event_spec mma8452_accel_events[] = { { + //trasient event .type = IIO_EV_TYPE_MAG, .dir = IIO_EV_DIR_RISING, .mask_separate = BIT(IIO_EV_INFO_ENABLE), @@ -1139,6 +1274,15 @@ static const struct iio_event_spec mma8452_transient_event[] = { BIT(IIO_EV_INFO_PERIOD) | BIT(IIO_EV_INFO_HIGH_PASS_FILTER_3DB) }, + { + //pulse event + .type = IIO_EV_TYPE_MAG, + .dir = IIO_EV_DIR_EITHER, + .mask_separate = BIT(IIO_EV_INFO_ENABLE), + .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) | + BIT(IIO_EV_INFO_PERIOD) | + BIT(IIO_EV_INFO_HYSTERESIS) + }, }; static const struct iio_event_spec mma8452_motion_event[] = { @@ -1202,8 +1346,8 @@ static struct attribute_group mma8452_event_attribute_group = { .shift = 16 - (bits), \ .endianness = IIO_BE, \ }, \ - .event_spec = mma8452_transient_event, \ - .num_event_specs = ARRAY_SIZE(mma8452_transient_event), \ + .event_spec = mma8452_accel_events, \ + .num_event_specs = ARRAY_SIZE(mma8452_accel_events), \ } #define MMA8652_CHANNEL(axis, idx, bits) { \ @@ -1368,9 +1512,11 @@ static const struct mma_chip_info mma_chip_info_table[] = { */ .all_events = MMA8452_INT_DRDY | MMA8452_INT_TRANS | - MMA8452_INT_FF_MT, + MMA8452_INT_FF_MT | + MMA8452_INT_PULSE, .enabled_events = MMA8452_INT_TRANS | - MMA8452_INT_FF_MT, + MMA8452_INT_FF_MT | + MMA8452_INT_PULSE, }, }; -- 2.7.4 From 1585214181061077177@xxx Mon Nov 27 10:20:50 +0000 2017 X-GM-THRID: 1585001820310808556 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread