From patchwork Fri Jul 24 17:43:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Clayton X-Patchwork-Id: 6862331 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 88F2E9F6FA for ; Fri, 24 Jul 2015 17:44:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 83DA220595 for ; Fri, 24 Jul 2015 17:44:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D6A7D205B8 for ; Fri, 24 Jul 2015 17:44:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752968AbbGXRns (ORCPT ); Fri, 24 Jul 2015 13:43:48 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:32997 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754703AbbGXRnq (ORCPT ); Fri, 24 Jul 2015 13:43:46 -0400 Received: by padck2 with SMTP id ck2so17653755pad.0; Fri, 24 Jul 2015 10:43:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=I90XQ0zE6w3oOjM1+1ZRBkhuz3pAD5AC1mQGBMqJgRI=; b=0B2ss2k37rVrBT8Ab3GZa1p0mG8L0LQk8gqE5u+UM42nNaFPILHq20rP2HjxSI9ml5 rX/qJGU9CcNMobGpEOn1s0P18GHBGz67IV6mfwy3+AtOk0I/iKbdTJhY1ofqRZDAKbPR u4w+KFssrl28evS9HsEVCwA5Yg5+oBnxFEY6XWs7LraCAKap1Xdu1MB26AgFTpYkqOSs lClCC9w+ODoZRNlsMW72OhZ9ovFVYhRB1WwgKNgJZPETph17brmI7Y1tP5J39FAPJRpo fq8zrMF+El4kU2HBX+PHEQY1F7cEwooStIyrJ6krtrMsBHPOuGxP1Rp/Jsl5Ln7NABLa ZdNQ== X-Received: by 10.70.134.226 with SMTP id pn2mr2940178pdb.53.1437759826053; Fri, 24 Jul 2015 10:43:46 -0700 (PDT) Received: from localhost.localdomain (68-185-59-186.static.knwc.wa.charter.com. [68.185.59.186]) by smtp.gmail.com with ESMTPSA id k5sm15684504pda.34.2015.07.24.10.43.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Jul 2015 10:43:44 -0700 (PDT) From: Joshua Clayton To: Dmitry Torokhov Cc: Dan Murphy , Nishanth Menon , Chanwoo Choi , Jaewon Kim , linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, Joshua Clayton Subject: [RFC PATCH 2/2] Input: evifpanel: show sliders through sysfs Date: Fri, 24 Jul 2015 10:43:21 -0700 Message-Id: <1437759801-24622-2-git-send-email-stillcompiling@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1437759801-24622-1-git-send-email-stillcompiling@gmail.com> References: <1437759801-24622-1-git-send-email-stillcompiling@gmail.com> 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.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable 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 sysfs file export the sliders in short int range slider sysfs files will be superceded by input events when we figure out what that should look like. Signed-off-by: Joshua Clayton --- drivers/input/misc/evifpanel.c | 112 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/drivers/input/misc/evifpanel.c b/drivers/input/misc/evifpanel.c index aa28e6c..0bda86f 100644 --- a/drivers/input/misc/evifpanel.c +++ b/drivers/input/misc/evifpanel.c @@ -14,12 +14,18 @@ #include #include #include +#include #define DRIVER_DESC "Uniwest EVI Frontpanel input driver" MODULE_AUTHOR("Joshua Clayton "); MODULE_DESCRIPTION(DRIVER_DESC); MODULE_LICENSE("GPL"); +struct fp_slider { + s32 sum; + s32 count; +}; + struct evifpanel { struct input_dev *dev; struct serio *serio; @@ -27,6 +33,8 @@ struct evifpanel { char name[64]; char phys[32]; unsigned char buf[8]; + s32 h_slider; + s32 v_slider; }; struct key_map { @@ -38,6 +46,30 @@ struct key_map { }; static struct key_map btns[] = { + { EV_ABS, ABS_X, 0, 3, 4 }, + { EV_ABS, ABS_X, 1, 3, 0 }, + { EV_ABS, ABS_X, 2, 4, 6 }, + { EV_ABS, ABS_X, 3, 4, 5 }, + { EV_ABS, ABS_X, 4, 4, 4 }, + { EV_ABS, ABS_X, 5, 4, 3 }, + { EV_ABS, ABS_X, 6, 4, 2 }, + { EV_ABS, ABS_X, 7, 4, 1 }, + { EV_ABS, ABS_X, 8, 4, 0 }, + { EV_ABS, ABS_X, 9, 5, 6 }, + { EV_ABS, ABS_X, 10, 5, 5 }, + { EV_ABS, ABS_X, 11, 3, 3 }, + { EV_ABS, ABS_Y, 0, 3, 2 }, + { EV_ABS, ABS_Y, 1, 6, 2 }, + { EV_ABS, ABS_Y, 2, 6, 3 }, + { EV_ABS, ABS_Y, 3, 6, 4 }, + { EV_ABS, ABS_Y, 4, 6, 5 }, + { EV_ABS, ABS_Y, 5, 6, 6 }, + { EV_ABS, ABS_Y, 6, 5, 0 }, + { EV_ABS, ABS_Y, 7, 5, 1 }, + { EV_ABS, ABS_Y, 8, 5, 2 }, + { EV_ABS, ABS_Y, 9, 5, 3 }, + { EV_ABS, ABS_Y, 10, 5, 4 }, + { EV_ABS, ABS_Y, 11, 3, 1 }, { EV_KEY, KEY_F1, 1, 6, 0 }, { EV_KEY, KEY_D, 1, 6, 1 }, { EV_KEY, KEY_N, 1, 7, 0 }, @@ -57,22 +89,63 @@ static void fp_check_key(struct evifpanel *fp, struct key_map *key) input_report_key(fp->dev, key->code, value); } +static void fp_slider_accumulate(struct evifpanel *fp, + struct fp_slider *slider, struct key_map *key) +{ + s32 value = !!(fp->buf[key->byte] & BIT(key->offset)); + + slider->sum += value * key->value; + slider->count += value; +} + +static s32 fp_slider_value(struct evifpanel *fp, struct fp_slider *slider) +{ + s32 value; + + if (slider->count) + value = (slider->sum * 0xffff / (11 * slider->count)) - 0x8000; + else + value = 0; + + if (value == -1) + value = 0; + + return value; +} + /* * Check buttons against array of key_map */ static void fp_check_btns(struct evifpanel *fp, struct key_map *key) { + struct fp_slider h_axis, v_axis; + + h_axis.sum = 0; + h_axis.count = 0; + v_axis.sum = 0; + v_axis.count = 0; + while (key->type) { switch (key->type) { case EV_KEY: fp_check_key(fp, key); break; + case EV_ABS: + if (key->code == ABS_X) + fp_slider_accumulate(fp, &h_axis, key); + else + fp_slider_accumulate(fp, &v_axis, key); + + break; default: break; /* ignore unknown types */ } key++; } + fp->h_slider = fp_slider_value(fp, &h_axis); + fp->v_slider = fp_slider_value(fp, &v_axis); + input_sync(fp->dev); } @@ -161,6 +234,37 @@ static irqreturn_t fp_interrupt(struct serio *serio, unsigned char data, return IRQ_HANDLED; } +static ssize_t v_slider_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct serio *serio = to_serio_port(dev); + struct evifpanel *fp = serio_get_drvdata(serio); + + return scnprintf(buf, PAGE_SIZE, "%d\n", fp->v_slider); +} + +static ssize_t h_slider_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct serio *serio = to_serio_port(dev); + struct evifpanel *fp = serio_get_drvdata(serio); + + return scnprintf(buf, PAGE_SIZE, "%d\n", fp->h_slider); +} + +static DEVICE_ATTR_RO(v_slider); +static DEVICE_ATTR_RO(h_slider); + +static struct attribute *attrs[] = { + &dev_attr_v_slider.attr, + &dev_attr_h_slider.attr, + NULL, +}; + +struct attribute_group fp_attrs = { + .attrs = attrs, +}; + static void fp_set_device_attrs(struct evifpanel *fp) { snprintf(fp->name, sizeof(fp->name), @@ -210,6 +314,11 @@ static int fp_connect(struct serio *serio, struct serio_driver *drv) goto fail2; } fp_request_fw_ver(fp); + error = sysfs_create_group(&serio->dev.kobj, &fp_attrs); + if (error) { + dev_err(&serio->dev, "failed to add sysfs group\n"); + goto sysfs_fail; + } error = input_register_device(input_dev); if (error) { @@ -221,6 +330,8 @@ static int fp_connect(struct serio *serio, struct serio_driver *drv) fail3: serio_close(serio); +sysfs_fail: + sysfs_remove_group(&serio->dev.kobj, &fp_attrs); fail2: serio_set_drvdata(serio, NULL); fail1: @@ -236,6 +347,7 @@ static void fp_disconnect(struct serio *serio) struct evifpanel *fp = serio_get_drvdata(serio); input_unregister_device(fp->dev); + sysfs_remove_group(&serio->dev.kobj, &fp_attrs); serio_close(serio); serio_set_drvdata(serio, NULL); kfree(fp);